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. Problem in handling Bluetooth headset with Froyo


I am Jasmeet Singh, working on one of the company which develop music
applications. We are facing an interesting problem where Bluetooth headset
buttons does not work with one of Motorola device having froyo but it works
with LG device with froyo too. In Motorola device, the key events are
received but the broadcast intent is not called.It might be another
application is intercepting it. Can you let us know how to resolve this



2. In case of crash intent

I was thinking it might be useful if the platform let an activity
either programmatically or in the application manifest register an
intent that would be fired if the activity crashes due to an error,
force closes, etc.

This could either launch a simpler help activity in the apk (which
might attempt to determine device type /version to report), or simply
launch the browser to go to the developer's support / bug report
page.  Either way, it would be better than all the "force closes on x"
observations cluttering up market comments.  (In neither case could
the intent exceed the permissions of the activity registering it)

Yes, there are some possibilities to find things left behind on the
next run and realize a problem occurred - but a more built-in method
for getting users practically in touch with support would seem


3. Fatal error during screen rotation


5. Using WebView with local data

6. ContextMenu setHeader -> get text from clicked listView item

7. Compass pointing a direction other than North