Simple Activity Related

by raqz » Wed, 31 Mar 2010 01:16:18 GMT


Sponsored Links
 I have this main class which displays a button and on click of the
button, the NextActivity class should be called. I have defined the
NextActivity class in the same package. But when I click the button,
the application closes stating there is some error.

But when i directly start an intent (un comment the last line). The
application goes there without displaying the Main class. Please let
me know what is the mistake i am doing.

package com.intents;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainClass extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btnOpen = (Button) findViewById(R.id.btnNext);
        btnOpen.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(getBaseContext(),
                        "You have clicked the Open button",
                        Toast.LENGTH_SHORT).show();
                Intent i = new Intent();
                i.setClassName("com.intents", "NextActivity");
                startActivity(i);

            }

        });
       //startActivity(new Intent( this, NextActivity.class));
    }
}

--



Simple Activity Related

by Mark Murphy » Wed, 31 Mar 2010 01:28:35 GMT


 


Use adb logcat, DDMS, or the DDMS perspective in Eclipse to find the
Java stack trace for your error.

In this case, it will be something about your Intent being malformed:


The above Intent is different than the one you said works:


Your first Intent does not have any sort of Context (e.g., your
Activity) associated with it, and so it will result in some exception
when you try to use it.

Instead, use the form of your second Intent, though you will need to
make it be MainClass.this instead of just "this" for it to compile.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/books 

--


Sponsored Links


Other Threads

1. Dialog Survival Over Configuration Change

Flipping between landscape and portrait is causing me a problem with
dialogs that are active at the time of config change.  The dialogs
survive (which I think is good), but I have the problem that some of
my dialogs contain dynamic content which would need to be refreshed in
the dialog views.  All that content disappears from the dialog views
after the config change.

I thought it would be easier to do a dismissDialog() on restoration in
onCreate(), letting the user press the button that shows the dialog.
I successfully save and recover the dialog id, but when I attempt to
dismissDialog(id) I get an IllegalArgumentException: no dialog with id
1 was ever shown via Activity$showDialog.

Ok, so that doesn't work, and I still have that messed up dialog up on
the screen that I want to get rid of.  How can I do that?  Are there
any other reasonable alternatives?  Thanks.
--~--~---------~--~----~------------~-------~--~----~

2. Where do donations end and payments begin.

I've been told that CashLog which is available via Market will reduce it's
functionality to only running on "odd days" unless a "donation" is made via
the authors web site.

Doesn't this sound more like a payment for the app than a donation?, Isn't
this against Market T&Cs which prevent developers charging for apps which
they got for free?, Isn't it also against the T&Cs to take payments outside
of Market for an app?

This also begs the question of is this a common practice?

Al.

---

* Written an Android App? - List it at http://andappstore.com/ *

======
Funky Android Limited is registered in England & Wales with the 
company number  6741909. The registered head office is Kemp House, 
152-160 City Road, London,  EC1V 2NX, UK. 

The views expressed in this email are those of the author and not 
necessarily those of Funky Android Limited, it's associates, or it's 
subsidiaries. 



--~--~---------~--~----~------------~-------~--~----~

3. Bitmap and pixel access

4. Timer Help (Time Stamp my code)

5. Samsung I7500 Media Capabilities

6. Fwd: Please unsubscribe joesensp...@gmail.com Was: Fwd: Android 1.5 SDK now available (Action Required) (Action Required)

7. Parsing &#xx; characters in XML