coolcool1994
coolcool1994

Reputation: 3804

How to finish an Activity (Before calling an new one)

I know about finish() method but is there a way to finish an activity completely before calling a new activity?

if you do

startActivity(intent);
finish();

You are starting a new activity before closing the previous activity completely.

Is there a way to close an activity completely before calling a new one?

Thanks a lot in advance.

EDIT: I need this because the old activity is a drawing file. The new activity is a listView activity. When a user close drawing file and start listView, that drawing file doesn't show up in listView. When I update listView using onClickListener of a button afterwards, listView gets updated - I think this is because the previous activity which was using the file is closed completely.

Upvotes: 1

Views: 945

Answers (3)

coolcool1994
coolcool1994

Reputation: 3804

I put Intent intent = new Intent(iContext, MainActivity.class); startActivity(intent);

at the end of the onDestroy. The listView now gets updated when the new activity shows up. Thanks for the help guys tho!

Upvotes: 1

MuraliGanesan
MuraliGanesan

Reputation: 3261

Try this,

Add nohistory in Your manifest.xml.

android:noHistory="true"

else,

Intent I = new Intent(A.this, B.class);
startActivity(I);
 A.this.finish();

This A activity will be close

Upvotes: 3

Shadow
Shadow

Reputation: 6899

Use this.finish(). or

use android:nohistory="true" in Android Manifest for an activity.

Even you can use System.exit(0).It will close the previous activity.

Upvotes: 2

Related Questions