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
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();
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.
无法在Activity2中完成Activity1。在进入activity2之前,有一种方法是必须使用finish()销毁activity1。
在test2 Activity中,您可以创建公共静态method() ,其中包含一个运算符finish() ...然后只需在Activity test1中调用此方法
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.
}
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.