how to start application in last viewed activity in previous session

by greg » Thu, 22 Apr 2010 02:30:08 GMT

Sponsored Links
 I'm writing an application consisting of several activities and, on
restarts, I'd like the application to initially display the
application's activity that was the last to display in the
application's previous session.

I save information about the last activity in SharedPreferences and
I'm trying to start that last activity with a call to
startActivity(intent) from my Application's onCreate handler.  The
problem is that if I don't set the intent's FLAG_ACTIVITY_NEW_TASK,
the result is a run-time exception message in logcat suggesting that I
should set the flag.  And if I set that intent flag, the correct
activity gets started but doesn't fully initialize resulting in null
pointer exceptions (which don't occur when I don't attempt to start
the activity from my Application class).

- - -

W/dalvikvm(  805): threadid=3: thread exiting with uncaught exception
E/AndroidRuntime(  805): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime(  805): java.lang.RuntimeException: Unable to create
application com.test.tangled.TApplication:
android.util.AndroidRuntimeException: Calling startActivity() from
outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK
flag. Is this really what you want?

- - -

Any tips on how to correctly start a particular activity from the
Application class's onCreate handler?



Other Threads

1. How to know if child activity exit by unexpected exception (onActivityResult() is not called)


I have faced with issue about startActivityForResult() and
onActivityResult(). If child activity started by the
startActivityForResult() exit by unexpected exception the
onActivityResult() is not called and I have no any ideas how can I
handle this to get application working in a fail-safe manner ?

When my code runs child activity with startActivityForResult() it
awaits until onActivityResult() will be invoked to get working
further, but onActivityResult() is not calling and my code is "hang-
up" (logically).

So the question is how can I handle all possible ways the child
activity is finished (normally and by unexpected exception) to get
fail-safe code ?

I have check the documentation for this issue but have found nothing
relating issue.

Thanks in advance!


2. Delete Contact field value in SDK early 5

HI All,
I am trying to delete Contact field value in SDK early 5. I am using
update method of ContentResolver for update value like that

ContentResolver resolver =
ContentValues cv = new ContentValues();
int count = resolver.update(Contacts.People.CONTENT_URI, cv, "_ID =
'1'", null);

and everything works fine (count = 1) but if I`am trying to delete

ContentResolver resolver =
ContentValues cv = new ContentValues();
int count = resolver.update(Contacts.People.CONTENT_URI, cv, "_ID =
'1'", null);

nothing happens but count = 1 again . Also I`m replace
Contacts.People.CONTENT_URI to
Uri peopleUri =
ContentUris.withAppendedId(Contacts.People.CONTENT_URI, 1) but nothing
Any ideas?


3. Seeking advice on a first program (includes general idea, just implementation advice.)

4. Contact added through API does not get synced

5. Trying to move multiple widgets at the same time

6. Senior Android developer Position- Las Vegas; 6 months min

7. how to disable auto pdp context activate feature?