7

I have an application with several Activities. My A Activity has the Manifest Intent filter parameters: action.MAIN and category.LAUNCHER. after its being loaded I call Activity B and finish() A since I don't use it anymore.

After I run my application, go from Activity A to B and press the Home button, when I relaunch it from the applications menu or from the Market app for ex.(not by a long press on the Home button), starts from the A Activity and do not save its last Activity B.

I definitely know that this is possible to relaunch an application from its last Activity (some applications from the Market do support it) and I think that this can be determined by the Manifest parameters but I don't know which one.

does anyone know how to implement it so my application can relaunch from its last Activity B?

Thanks ayanir

1
  • Have you figured it out? If so, please share with us... Jul 27, 2011 at 15:19

3 Answers 3

5

Though I know this is an old question, I was struggling with this very issue and couldn't find an answer on SO. So, here is my (very newbie) answer:

No, I do not think it's possible to do this by messing with the manifest - you can only launch one fixed activity per app from the home screen. What you can do, though, is launch whatever activity you want from that starting point, and Android can do it quickly enough that you never see the first one.

Though this feels very much like a hack, I implemented this routing in the starting activity's onResume() method, and used sharedPreferences to keep track of which activity to launch:

final Class<? extends Activity> activityClass;
        SharedPreferences prefs = getSharedPreferences("sharedPrefs", MODE_PRIVATE);
        int activityID = prefs.getInt("whichActivity", -1);
        if (activityID  == Constants.ACTIVITY_ID_MAINSCREEN) {
            activityClass = MainScreen.class;
        } else {
            activityClass = null; return;
        }
        Intent newActivity = new Intent(this, activityClass);
        this.startActivity(newActivity);
1

There have been a number of very similar questions lately. It's a good idea to search the site first to ensure that duplicate questions don't get asked.

For example, the question linked below says that this behaviour was happening because the developer was starting their application using the Eclipse debugger. Another person was having this problem because they were launching the application directly from Eclipse, rather than starting cleanly by manually pressing the launcher icon.

Android: keep task's activity stack after restart from HOME

1
  • Note that this behaviour has been fixed in the 0.9.6 release of the ADT plugin for Eclipse. Mar 14, 2010 at 14:47
0

so there are a few things to consider when developing Apps in Android. And one of the big things is the Application Lifecyle, if you haven't yet then I would suggest this video. What happens is that an application can be killed and reset at any point in time and you need to save the state of your application so that you can restore it at any time. If you open your App from the Launcher you will always go into the Activity that starts the app, if you want to skip to the next Activity you need to store that information and then jump to the Activity in your code.
Also have a look at this documentation about SavingPersistentState

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.