Reputation: 839
i have two activity such as test1 and test2. i want to close test2 activity in test1 activity.i need to close test2 activity in test1 activity button click. how to do it,
test1activitybutton.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
// need to close test2 activity
}
});
i need to close in another class activity as above
Upvotes: 0
Views: 261
Reputation: 16872
You probably need no button: if you turn the screen, you will return to another instance of your Activity subclass. :)
Did you see this: Finish an activity from another activity ? Also, Finishing Activity from another activity
Upvotes: 0
Reputation: 3215
can you try this i am not sure it will work or not.
startActivityForResult(intent, requestCode);//here start activity t2
public void onClick(View v)
{
finishActivity(requestCode); //it will finish your t2 activity requestCode should be same.
}
Upvotes: 0
Reputation: 1056
In test2 Activity you can create public static method(), which contains one operator finish()... Then just call this method from Activity test1
Upvotes: 0
Reputation: 920
In your test1 activity after class declaration.
Activity t1;
and oncreate of test1 activity
t1=this;
In your test2 activity inside onclick listener
Yourtes1activityobject.t1.finish();
Upvotes: 1
Reputation: 4092
It not possible to finish the Activity1 in Activity2.One way is possible before you go to the activity2 you have to destroy the activity1 using finish() .
Upvotes: 0
Reputation: 9117
You can't and shouldn't be doing this. At a time, only one activity is on the foreground, and the other activities is paused. So, the background activities are not active, and no code on such an activity can be executed.
Upvotes: 0