I have an application with, let say, two activities. One of the activity is already launched and after pressing "home" button it is in background. Now, from the ANOTHER application the second activity is launched. And when this second activity is finished I got to the first launched activity, not in the application that started the second activity. Is it normal behaviour? If it is, is there some way to change it? I need to stay in the application that launches the second activity, and not in the application which this second activity from.
Related
I have an application that implements two activities. Activity A is for selecting some files on device and activity B is to show additional info while these files are processing. Both of them have singleInstance as launch mode.
On application's start activity A runs. Then this activity starts second activity B, that creates a notification. If I tap this notification or open running app from recents, it works fine and shows running activity B. But if I'd started application before and activity B is already running, launching it again from app menu causes showing activity A when old activity B is already running and accesible from notification bar.
So, what should I do to make application run only single activity at the same time and show second activity when called from launcher (if second activity once started and isn't finished)?
Your launcher intent should be mapped to a dummy activity, with no view (or may be a splash who knows !). In onCreate of that dummy activity you check if a state was saved previously and based on the state switch to the desired activity.
And how to set the state ? well lets try something simple. lets say when Activity A resumes we put "A" to some key in SharedPreference. if Activity B resumes we put "B" to the same key in preferences. Now your application goes out when Activity B was visible, the state saved would be "B", you launch from home screen, the dummy activity finds "B" in the state and launch intent to go to B else go to A.
I have an application which has two activities A and B. When application is installed and run for the first time then it always starts with A as it is declared as launcher activity in manifest.
According to workflow, after a few seconds, activity A is destroyed and activity B is started. So that, the root of task becomes B. Now, when user presses the home button and later comes to our app, activity B is resumed as expected. But, if application is left in background for a long time then the application is restarted as from the logs Application::onCreate() is called. However, I want that whenever the application restarts that is whenever Application::onCreate() is called (like in the second case) activity A should be started instead of B, in all other cases when application is not restarted activity B should be appearing. I am new to android and unable to figure out a solution. Any help is much appreciated.
Thanks in advance.
Use SharedPreferences : http://developer.android.com/reference/android/content/SharedPreferences.html
In the end of your activity A you should create a preference that save the a state of your app in the SharedPreference.
at the start of onCreate() of your activities check the state and start the correct activity.
My app works as launcher. 10 mins later another activity starts automatically. When this activity started, if user presses home button, he returns to the main activity. However, I want to change the launcher activity as the second one. It must be forbidden to return to the main activity even if he presses home button.
Instead of playing around with the intent filters, I suggest you create a blank Activity, with no UI, and register it as your launcher.
This Activity's sole role is to choose the correct actual Activity you wanna show, launch it as a new task, and then quit silently.
When my app crashes, it loads again in a random activity instead of being force closed.
When I call android.os.Process.killProcess(android.os.Process.myPid()) it follows that behaviour too.
I just want my app to force close if needed and let the user send me their reports.
What should I do to avoid that behaviour?
Are you sure it loads some random activity? Usually it loads the next activity on top of your app's activity stack.
from https://stackoverflow.com/a/7240460/262462:
start first activity (either splash screen, or whatever activity is currently at the bottom of the activity stack) with FLAG_ACTIVITY_CLEAR_TOP (which will quit all the other activities started after it, which means - all of them). Just make to have this activity in the activity stack (not finish it for some reason in advance).
call finish() on this activity
I have an activity A. now i start a service using
startService(new Intent(A.this,Service.class));
now after some times (since it is performing some task in background , you can move anywhere in phone , so lets stay at phone home screen) service stops and start an another activity B (now B is on Top) which show result. Current i am on screen B. my problem is when i am on B and press back , it does not show activity A. even if i exist from app(through back button) and again I launch the app it show activity B. since my starting activity is A so i want to show A not B. please guide me how can i do this.