Hello,
In my current application I have a class that extends the Application
class. Inside that class I have a Handler (ticks) and a Runnable
(tickEvent) and the tickEvent is being fired approx every 5 seconds.
When my main Activity is running this is working fine and I am using
the broadcast to capture the "pulse" as it were in the required
activities.
The problem occurs when the user presses the Home key. My handler and
runnable still run, but instead in this case I am trying to get a
PendingIntent to launch so it shows up in the status bar. Again this
works fine, however because I am not getting the right context
(probably because I am not creating the PendingIntent inside an
activity), then it creates a brand new activity. I can actually cope
with this, however I am wanting to clear the stack below so that the
user is taken back to the main menu Activity instead of the activity
they left it at. I have tried to put the flag
Intent.FLAG_ACTIVITY_CLEAR_TOP in but it's not working.
What I am trying to achieve is thus:- User launches game from menu and
then main Game Activity is shown, from this activity several others
can be launched depending on what the user wants to do. However, once
the Home key is pressed my game still needs to keep running but notify
the user. Upon a special event I want to take them to an Activity and
then from there back to the main menu (because this means the game is
over, so it's pointless showing any other activities). However what is
happening is that when my event happens and I show the activity, once
the back button is pressed (or I call finish()) they are dropping back
to the Game Activity.
Here is how I am calling my PendingIntent (from inside my class
derived from Application).
private void updateStatus(SporePet.hungerLevel level)
{
int flags = 0;
String msg = "";
Class noteClass = null;
Notification note = null;
NotificationManager mgr = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
switch(level)
{
case HUNGER_DEAD:
msg = "Your Pet has passed away";
noteClass = GameDied.class;
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP;
note = new Notification(R.drawable.notify_dead, "Spore
Pet Alert", System.currentTimeMillis());
ticks.removeCallbacks(tickEvent);
break;
case HUNGER_STARVING:
break;
}
mgr.cancel(900);
if(note != null && noteClass != null)
{
PendingIntent pi = PendingIntent.getActivity(this, 0, new
Intent(this, noteClass), flags);
note.setLatestEventInfo(this, "Spore Pet Alert", msg, pi);
mgr.notify(900, note);
}
}
Obviously as you can see once the Pet has died there is nothing else
that can be done, so from the GameDied.class I want to go back to my
Main Activity, but I am not sure how to achieve this. Could someone
please advise ?
Regards
Anthoni
--
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