> I have a skeleton system of Activities that will eventually be filled
> with GUI elements, but for now I just want to work on a particular
> aspect of the project without developing the initial GUI parts first.
> But, when I try to launch an Intent from onResume, I get a
> RuntimeException in ActivityThread.performResumeActivity.  What is
> wrong with the following code?
>
> public class Test extends Activity {
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>     }
>
>     public void onResume() {
>               Intent i = new Intent(this, SecondActivity.class);
>               this.startActivity(i);
>     }
>
>     public class SecondActivity extends Activity {
>         @Override
>         public void onCreate(Bundle savedInstanceState) {
>             super.onCreate(savedInstanceState);
>             setContentView(R.layout.main);
>         }
>     }
> }

What you are doing makes no sense.

When the Test activity starts up, onResume() is called. At that point, you
start SecondActivity, so the user is presented with SecondActivity right
away. The user back-buttons out of SecondActivity, at which point
onResume() on Test gets called...starting up SecondActivity again.

Do not call startActivity() in onResume(). Do it based on user input
(menu, button, list item click, etc.).

Beyond that, look at your stack trace to find out the source of your
exception (use adb logcat, DDMS, or the DDMS perspective in Eclipse to get
the Java stack trace). Perhaps SecondActivity is not registered in your
AndroidManifest.xml file?

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to