How to kill sub activities and bring activity to top of stack
You can use the FLAG_ACTIVITY_CLEAR_TOP flag on the intent to restart activity A.
How to bring an activity to foreground (top of stack)?
You can try this FLAG_ACTIVITY_REORDER_TO_FRONT
(the document describes exactly what you want to)
Android Popping off the Activity Stack
If A is already running, you can use the FLAG_ACTIVITY_CLEAR_TOP flag when starting an intent to go back to A.
See also, similar questions:
How to clear current activities in the stack?
how to kill sub activities and bring activity to top of stack
Android popping activities off the stack - yes, again
You could just add singleTop
to your main activity.
Here, read about it. It brings the existing instance of the activity rather than create a new one.
http://developer.android.com/guide/topics/manifest/activity-element.html
http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_SINGLE_TOP
Android: Remove all the previous activities from the back stack
The solution proposed here worked for me:
Java
Intent i = new Intent(OldActivity.this, NewActivity.class);
// set the new task and clear flags
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
Kotlin
val i = Intent(this, NewActivity::class.java)
// set the new task and clear flags
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(i)
However, it requires API level >= 11.
How to kill an activity
Call new screen using
Intent intent = new Intent(activity,secondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(intent);
When you hit home button , application get resume. so next time it open the same page. for this use
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
startActivity(new Intent(Activity1.this,spalshscreen.class));
}
on restarting , you can also reset flag using Intent.FLAG_ACTIVITY_CLEAR_TOP
if activity is in stack.
Finish an activity from another activity
Make your activity A in manifest file:
launchMode = "singleInstance"
When the user clicks new, do
FirstActivity.fa.finish();
and call the new Intent.When the user clicks modify, call the new Intent or simply finish activity B.
FIRST WAY
In your first activity, declare one Activity object
like this,
public static Activity fa;
onCreate()
{
fa = this;
}
now use that object in another Activity
to finish first-activity like this,
onCreate()
{
FirstActivity.fa.finish();
}
SECOND WAY
While calling your activity FirstActivity
which you want to finish as soon as you move on,
You can add flag while calling FirstActivity
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
But using this flag the activity will get finished evenif you want it not to. and sometime onBack
if you want to show the FirstActivity
you will have to call it using intent.
Related Topics
Android, How to Create Option Menu
Android: Automatically Choose Debug/Release Maps V2 API Key
Applying Colorfilter to Imageview with Shapeddrawable
How to Save Image in Shared Preference in Android | Shared Preference Issue in Android with Image
Error:Execution Failed for Task ':App:Transformresourceswithmergejavaresfordebug'
How to Save Images into Database
Camera Intent Not Working with Samsung Galaxy S3
Android Java.Lang.Illegalstateexception: Couldn't Read Row 0, Col 0 from Cursorwindow
Retrieve String Out of Addvalueeventlistener Firebase
How to Get Toolbar from Fragment
How to Use Room Persistence Library with Pre-Populated Database
Mask Imageview with Round Corner Background
Android - Emulator in Landscape Mode, Screen Does Not Rotate
Android: How Get the Status-Code of an Httpclient Request
Livedata Prevent Receive the Last Value When Start Observing