I have activity stack in my android application.Suppose A and B.When the application starts the Activity A is visible.From this activity i call Activity B using startActivityForResult method.Now from here if i press Home button of device then activity runs in background that is OK.But when i relaunch the application by taping on activity icon a new instance of activity is start and show activity A rather showing the activity B.Please help me in this.Any help would be highly appreciated.
Check out if your launchMode of the Activity A is SingleTask.
You can try calling activity B using getApplication().startActivity(myIntent);
Related
I have two activities A & B. Activity A is launcher activity & I want to Run Activity B in the background when i launch my app. I dont want to go on activity B. I just want to run in background. Also I don't want change this activity to service.
My Question is that Can we run a activity in background? if yes then please give me some sample of code how can we run?
You cannot really run an Activity on background! When an activity is not on foreground it gets to onStop and then the system could terminate it, to release resources, by onDestroy method! see Activity Lifecycle
I have a splash activity and a MainActivity in which I open some activites:
Resume: SPLAH--> MAIN --> A or B or C and from A or B or C I open more activities
but when I start activity and push the back button from A or B or C the app is finished and I would like the MAIN would be active.
I start activities so:
Intent i = new Intent(this, Listado_mapas.class);
this.startActivity(i);
this.overridePendingTransition(R.anim.entrada_derecha, R.anim.salida_izquierda);
It doesn't work but nevertheless when I open with the same way from B to another activity it backs prefectly. ¿?
Thanks in advance
I don't understand this behaviour !!
why it's running ?
I reviewed my code and in the first Activity SPLASH I had FLAG_ACTIVITY_NO_HISTORY.
I have 2 activities Activity A and Activity B.
Activity B start on click of button in Activity A.
I want to start Activity B in background when the Activity A is created and move to Activity B when I click on button in Activity A.
Please help me. Thanks
If you want something that runs in background , then you go for service not the activity
Have Activity A ,here am retrieving data from server .On click of button am finishing current activity and start B activity ,on click of button again i want to go A activity by finishing B activity but i dont want to reload A activity
You should have a look at the lifecyle of an activity and the activity stack. developer.android.com/guide/components/tasks-and-back-stack.html. To know more about the this developer.android.com/training/basics/activity-lifecycle/index.html. Go through the links and you should able to solve your problem.
In my app I have a main activity that is started when the app is launched from the app drawer. In the app there is another activity B that can be launched from the main activity.
If I press home while in activity B to return to home, Activity B will be started instead of the main activity if I launch my app through the app drawer again.
Is there a way to make only the main activity start even if the user pressed home in activity B without using noHistory?
Any help would be appreciated!
You just don't want to keep state in B, on the Activity B onStop method, just call finish();
I set a separate android:taskAffinity for activity B