I have three activities A->B->C.when i am in B activity i click the home button and put the application to back ground(B->home).
When clicking on the my application icon in the home screen the Activity A is opened not activity B .but upon long pressing the home key,its showing that my app is running in background and clicking the icon open the Activity B as expected.
What was the problem?i didn't handle any home key event.How to prevent relaunching my application.
When you make a long press the dialog shows recently used app and not the ones ruuning at the moment. To make sure your activity is not killed go toSettings-> Applications-> Manage Applications -> Running tab.
Usually the behavior you described is cause by launchMode attribute in the manifest.
Check that you do not have anything there.
read more about "launchMode" attribute here.
Related
So my scenario is as such.
Let's say there is a MainActivity, which only job is to start, call installSplashScreen().setKeepOnScreenCondition { true } to show the Splash screen using the new backward compatible APIs, and then after checking some state it does startActivity(SomeActivity); finish()
Now we're on the SomeActivity and if we press the home button, the app is gone on the background. Then if we click on the launched icon, the SomeActivity is launched correctly, and the MainActivity's onCreate is never called, therefore the splash screen does not show again, and the SomeActivity shows instantly.
But if instead of pressing the home button, we press the back button, and the app is backgrounded that way, then when we click on the launcher icon, the MainActivity's oncreate is called again, and the splash screen icon flashes for a tiny fraction too making it look jarring.
My question is, does this sound like it's some wrong configuration on my part, or am I stuck with this behavior as long as I am not on a single activity architecture?
You are confused. Pressing the BACK button does not "send the app to the background". The default behaviour of the BACK button (assuming that you don't override this and provide your own behaviour) is to finish the current Activity. Normally this will take the user to the previous Activity in the current task. In your case, there is no other Activity in the task stack, so the current task is empty. This may appear to the user as "the app is sent to the background", but in reality there is nothing in the background. Your app's task is empty and so it is gone.
When the user then taps the app icon on the HOME screen or taps on the app's task in the list of recent tasks, there is no existing task to bring to the foreground, so the app is started again by creating a new task and launching the root Activity (in your case MainActivity) into the newly created task.
If you want the BACK button to just put your app into the background (instead of calling finish() on SomeActivity, which is the default behaviour) then just override onBackPressed() in SomeActivity and do this instead:
moveTaskToBack(true);
It seems like there is no solution to what I am facing as long as the Activity I want to resume to is not the Launcher activity.
From the the docs:
"Root launcher activities are activities that declare an Intent filter with both ACTION_MAIN and CATEGORY_LAUNCHER. These activities are unique because they act as entry points into your app from the app launcher and are used to start a task.
System behavior on Android 12 and higher
The system moves the activity and its task to the background instead of finishing the activity. This behavior matches the default system behavior when navigating out of an app using the Home button or gesture."
Reading the docs about the new back behavior on Android 12 and onwards tells us that pressing back when you got nothing else on the stack will act as if you pressed the home button.
There's a big exception here, and that is that when you re-open the application, if the one you just popped was not the launcher activity, it will then still need to launch that launcher activity and can't resume from where you left off in a hot state, exactly the reason why I am seeing the splash screen again.
So I think my best bet is to either ignore this for now, or fix my app to be a single-activity app, or at least keep the launcher activity be the top-level one that you exit the app from by pressing back
To indicate a couple of examples, if one wants to experience what I mean, the reproduction steps are to:
Open the app
Press the back button which will send you out of the app to the home screen
Click on the app icon again
As of today, apps like Google Photos, and Google Podcasts don't show the splash again. In contrast, apps like Google Maps, Twitter, Spotify do show the splash again for a brief second.
to call the launcher activity every time you have to clear the stack that means you have to use a flag in your manifest to tell your app not to keep activity in background try android:launchMode="singleTask" inside your activity tag in manifest the activity that you want to be killed everytime you go to background, and as far as how much time splash should be showing you can use timer for that after the timer is finished then your someActivity will be called.
I have 3 activities ( say A, B, C were A-is the Launch activity). When I press home button when at activity C, app goes into background. After that, I took my app through all apps list menu. At that time, my launch activity is showing (activity A). When I press back button, It goes to previous activity (C). I want to retain in the same activity (C) while coming back from background. When I run application through Eclipse, It works fine. But when I send Apk file through mail and run it in device, It fails (previous problem occurs ).
I tried with
android:launchMode="standard"
AND
android:alwaysRetainTaskState="true"
in my launch activity (Login activity or A). Any body please help me, Thanks in advance.
Follow following steps to insure that you are following the right practice:
1. Make sure you are using finish(); on the Activity A or B if you want to finish it and dont if you want the back button functionality.
2. Try Implementing onpause() and onresume() even if you are not going to perform any functionality in them. Use super() for them there.
3. Also, in android when you start an activity by clicking on the icon instead of resuming it from already running activities, it exhibits a different behaviour.
In my app, I've noticed a difference when using the home button.
Ex.
I press app icon, and the app starts op like it should with Activity(A). When I press Home button, the app gets minimized as it should. When I press app icon again, the app resumes with onResume() with Activity(A)
Now for the tricky part.
From the app, when I press my "Start button" another Activity(B) is launched, and focus is changed to the new Activity(B). When I press Home, the app minimizes (like its supposed to).
And now for the problem:
If I press the app icon, my app starts op from the very beginning with Activity(A) where my start button is. (And not with ActivityB which I just minimized)
If I do the scenario over again (Start app - > focus to Activity(B) -> Press home) and this time long press the home button, and the "Recently launched" comes op, and I select my app. Now the focus resumes to Activity(B)
Both Activity(A) and Activity(B) are set to SingleTop.
My question is, why is there a difference when using the different combinations of LongPress home + icon and OneClick Home + icon
First think about this... when you are opening your application ...
your first Screen will be shown may be it is SplashScreen.
and if..you are in Activity A and goes to B and then Press BACK obviously
you will see Activity A.
So now when you Long Press Home button..That shows you recent apps with saves state of last shown Activity..that's why when you open from there..you see Activity B directly without SplashScreen.
And Simple Pressing Home Button Once,you are went to Home Screen from where you are opening Applications Screen which is Launcher Screen..from there If you press any Icon that particular app will be Launched(Means to open the app from its Main Activity that is defined in Manifest with Intent Filter set to Launcher)...That's why opening an app from there will always show you,your SplashScreen.
This is not a Bug,not an Issue..This is how the Android is designed to work.
Same button is used to perform two different events,cause they are related..but It's not like both event performs the same actions.
Continuing to the above scenario, I have an App with Login Screen which takes me to Activity A -> OnClick of some button takes me to Activity B.
when there is a LongPress of Homebutton,and I start another App and stay on it for considerable time like say 5-10 minutes. Then again When i Long Press home button, and return to my Activity - It starts with Activity B .. which is correct.
From Activity B if i press Back key, It does take me to Activity A but there is a Black screen shown. In normal cases, It shows me a a list view of Dynamic XML data.
I have Activity A which calls B, at which point let's say the user presses the home button:
1) If the user long presses the home button and brings out the recently launch application, it will bring the user back to activity B.
2) If the user opens my application via the shortcut ( pressing the icon of the application), it will create another instance of Activity A.
I did not set any launchMode for my activity, so I guess it's launchMode="standard", the default behaviour I want is to go back activity B.
Why is point number 2 happening? I always thought that both of the actions will lead to the same result.
Every time it should call activity B unless Dalvik machine thinks that activity B is a background process and the process space might be required for other applications,
At that point your activity may be killed and it may launch afresh when you click the icon.
It's weird...I did a total uninstall and reinstall of the app.
Without declaring launchMode, it's default to "standard", and it works just as designed.
I am working on my own home launcher replacement and it works fine but one thing bothers me. When I press a home key, current home activity (the one defined in manifest as main/defualt/launcher/home) restarts - current activity instance onpause is executed and oncreate is fired again, so new activity is brought up.
On the other hand, ADW launcher and LauncherPRo does not behave like that - I do not a refresh like in my case. Launcher Pro even can do several actions:
If you are on the main screen with app icons, it zooms out to see a snapshot of all screens,
If you open a drawer and press Home, it just go back to the main screen.
Any ideas how to do that?
I just did a very simple prototype from scratch with just one activity (defined in manifest as main/defualt/launcher/home) and I see the same thing - it gets recreated if I press Home.
Add
if (!isTaskRoot()) {
finish();
return;
}
to the onCreate() of your first Activity (see Android application restarts when opened by clicking the application icon).
Add android:launchMode="singleInstance" to your <activity> element in the manifest.