Activity Lifecycle Question

by Gil » Mon, 29 Sep 2008 05:56:38 GMT

Sponsored Links
 I have an activity which is started by the intent set by my app in the
status bar. My activity uses the singleTop launchMode. I go through
the following sequence of events:

1) My activity is initially not visible.
2) I get a notification in the status bar. I click on the new
notification which starts my activity.
3) While my activity is still visible I get a new notification in the
status bar. I click on the new notification again.

My question is the following: What method should I override to learn
that my activity is being "started" when the user clicks on the
notification the second time?

I thought that onNewIntent should be called but it is not. onNewIntent
does get called each time I click on the notification if my activity
is initially started from the home screen (but not if it is initially
started by clicking on the notification).


Activity Lifecycle Question

by Megha Joshi » Mon, 29 Sep 2008 08:51:50 GMT

 When setting the Notification intent, are you using the Flags CLEAR_TOP and
ie. Intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |

More explanation about these launch modes is given in the docs below: #FLAG_ACTIVITY_CLEAR_TOP

2008/9/28 Gil <[EMAIL PROTECTED]>


Sponsored Links

Activity Lifecycle Question

by Gil » Mon, 29 Sep 2008 10:12:09 GMT

 Awesome! You saved the day ... again.

Activity Lifecycle Question

by Guillaume Perrot » Mon, 29 Sep 2008 18:54:24 GMT

 "A situation you will often run in to is when another entity (such as
the SearchManager or NotificationManager) starts one of your
activities. In this case, the Intent.FLAG_ACTIVITY_NEW_TASK flag must
be used, because the activity is being started outside of a task (and
the application/task may not even exist). As described previously, the
standard behavior in this situation is to bring to the foreground the
current task matching the new activity's affinity and start the new
activity at the top of it. There are, however, other types of behavior
that you can implement.

One common approach is to also use the Intent.FLAG_ACTIVITY_CLEAR_TOP
flag in conjunction with NEW_TASK. By doing so, if your task is
already running, then it will be brought to the foreground, all of the
activities on its stack cleared except the root activity, and the root
activity's onNewIntent(Intent) called with the Intent being started.
Note that the activity often also use the singleTop or singleTask
launch mode when using this approach, so that the current instance is
given the new intent instead of requiring that it be destroyed and a
new instance started."



activity lifecycle question

by Rico » Wed, 03 Feb 2010 04:15:39 GMT

 I have a question about working with the activity lifecycle in

Let's suppose my app has some music playing.

I want the music to continue playing in the following scenarios:
- User changes screen orientation
- User browses different activities within my app

I want the music to stop playing in the following scenarios:
- User presses home button
- Another app comes to the foreground (e.g. Google talk message comes
in and user chooses to reply, or user presses call-button to launch
dialer app, or user presses camera button to launch camera app, etc.)

What's the cleanest way to accomplish this?

Thanks for reading and any help you can offer.


activity lifecycle question

by Aniruddh Bajirao » Wed, 03 Feb 2010 04:29:45 GMT

 >From the requirements that you mentioned, it seems to me that you need to
handle the onPause() ... (for the case when ur app is swapped out or another
app is on the screen), onResume(), onStop() and use the
OrientationEventListener (onOrientationChanged)
For the music player though, it might make sense to have a service.


Other Threads

1. Pending intent not detecting onCreate

I have the following code in a static function in my application

                Intent defineIntent = new Intent(context,
                PendingIntent pendingIntent = PendingIntent
                                .getActivity(context, 0, defineIntent, 0);

                views.setOnClickPendingIntent(, pendingIntent);

                // Tell the widget manager
                appWidgetManager.updateAppWidget(appWidgetId, views);

custom activity's based on user clicks on your widgets. However even
though Logcat says Starting Activity: Intent {......} my activities on
create function never gets called!

Note my Activity is as follows:

public class ToggleIntentActivity extends Activity {
        protected void onCreate(Bundle savedInstanceState) {
                Log.e(QuickerCutWidgetManager.TAG, "On create");

Any ideas?

2. Spry onload command

Have added a IU that is fading one image to the next with Spry at
onload.  Only getting black screen on ADP1.

3. Build OpenCORE outside of Android

4. upgraded to 1.5 and apps wont run

5. Regarding AbsoluteView being deprecated in 1.5

6. Status bar in screen

7. switch / if statement, efficiency question