3

I'm using a custom Launcher application with Widgets that are used to launch (and provide status updates) for an application.

The application consists of a few Activities - let's call them A, B and C for simplicity.

A is the launched Activity. The user proceeds from A to B and then to C (never in any other order).

At any time the user can press the 'Home' button on the remote control and return to the launcher application.

If the user then presses the 'Back' button on the remote control they always return to the Activity they were last using (A, B, or C).

However, if they click on the widget (rather than pressing back) the Activity that is brought to the front seems inconsistent!

So, here is an example of what happens

From (custom) launcher, use widget to launch application
Activity A appears
User presses a button that launches Activity B
Activity B appears
User presses 'Home'
Launcher appears
From (custom) launcher, use widget to launch application
Activity A appears NOT B

Sometimes I get Activity B instead of Activity A - but I'm not sure under what circumstances. I want to get the Activity at the top of the stack to be displayed and never any other Activity (Activity B in the example above).

I've read Google's documentation about the Activity flags ("single-task", "single-instance", etc...) but nothing seemed to jump out as the solution to my problem.

In my case, Activities A, B, C only make sense when run in that order - and it never makes sense to see a previous activity unless you explicitly go back to it.

I'm not sure if the problem is the way the widget is launching the application or whether there is something I need to specify in my manifest or something else.

Any ideas?

Thanks,

Dan

Dan
  • 31
  • 3

2 Answers2

0

I'm sorry, but this is not an answer, but rather some additional information related to that same question.

I have found a pattern for Activities when relaunched after home button is pressed.

See my question for all my research:

Android Activity Stack is not working as stated in the docs - last activity in task stack not shown

Hope this can be of help...

I have been reading that the suggested fix for this strange behavior is the use of a "Dispatcher" class as Main that will launch the activity based on the application state...or you can also keep track of all the activities opened that need to be restored...but this can become really cumbersome when having a complex UI application design.

Community
  • 1
  • 1
Valdez V.
  • 252
  • 5
  • 18
0

Isn't that what's supposed to happen? Isn't your widget launching activity A? Would you expect it to launch activity B if you are asking it to launch activity A?

(Althought you say that you get B launched sometimes. Isn't this related to the app being forced out of the memory?)

Axarydax
  • 16,353
  • 21
  • 92
  • 151
  • Thanks for the response. The worrying thing is the seemingly randomness to which Activity is displayed after returning to the application. The documents aren't very clear on the subject of how this is supposed to work. I read that the activities in a task are never re-ordered (unless you specifically request that) and that launching the application with the Intent flag FLAG_ACTIVITY_NEW_TASK should either start a new task or if that Activity is already running, bring that task to the foreground (see http://developer.android.com/reference/android/content)/Intent.html#FLAG_ACTIVITY_NEW_TASK). – Dan Jan 20 '11 at 09:30
  • Also - to address the issue of running out of memory - I don't believe that is the case because I can see from logcat that the Activities are all still running. – Dan Jan 20 '11 at 09:39