[英]Notify other activities of the same application to finish it self from one activity
[英]finish activity from an other one
我有一个菜单事件活动:
public class GlobalMenu extends Activity{
private MenuItem item;
public boolean event(MenuItem item){
this.item = item;
// Handle item selection
switch (this.item.getItemId()) {
case R.id.menu_stop:
finish();
return true;
}
return true;
}
}
我这样使用
GlobalMenu gm = new GlobalMenu();
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return gm.event(item);
}
但是完成不起作用,我想我需要将其与应用程序链接,但是我不知道该怎么做
谢谢
首先,您不能创建Android活动的对象或实例。 像这样
GlobalMenu gm = new GlobalMenu();
您必须将GlobalMenu Activity的上下文传递给其他Activity或Class,然后在此方法上调用finish。
喜欢,
((GlobalMenu)mContext).finish();
这里的mContext是GlobalMenu Activity
的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.