Omri Attiya
Omri Attiya

Reputation: 4037

How to close an activity from another activity

I need to close activity. But not right after its on pause. I need to close it when I'm in other activity.

how can I do that?

Upvotes: 1

Views: 16710

Answers (3)

sherin
sherin

Reputation: 1091

Try this method too,

For Android Studio:

 ((Your Main Activity) Activity()).finish(); //this will close that corresponding activity 

or

android.os.Process.killProcess(android.os.Process.myPid()); //using this you can exit from the whole activity  for both Eclipse and Android studio

For Eclipse:

  finish();

Or

private void kill_activity()
   { 
  finish();
  }

Upvotes: 2

Waqar Ahmed
Waqar Ahmed

Reputation: 5068

you need to pass context of activity(that you want to close) to other activity and then you can call

(Activity(context)).finish();

Upvotes: 0

Asheesh
Asheesh

Reputation: 581

Just pass object of activity which you want to close to the activity from where you want to close it and do some thing like this obj.finish();

Upvotes: 0

Related Questions