在一个应用程序中,有 3 个活动,A,B,C。A是登录。B是菜单,C是设置值。工作线:A->B->C。在 C 中,有一个名为 logout 的按钮。单击注销时,我将Result设置为B,完成C并启动A。在B中,我覆盖onActivityResult,当结果代码正确时,我完成B。但是测试数据显示当A被C重新启动时,B没有完成. 欢迎解决!这是代码:
Activity A: LoginActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
login=(Button) findViewById(R.id.login);
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(LoginActivity.this,MenuActivity.class);
startActivity(intent);
LoginActivity.this.finish();
}
}
}
Activity B: MenuActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
setting=(Button) findViewById(R.id.login);
setting.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent settingintent=new Intent(MenuActivity.this, SettingActivity.class);
startActivityForResult(settingintent,1);
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==1){
switch(resultCode){
case RESULT_CANCLED:
break;
case RESULT_OK:
MenuActivity.this.finish();
Log.i(TAG, "I'm killed"+System.currentTimeMillis());
break;
}
}
}
Activity C: Setting.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
logout=(Button) findViewById(R.id.login);
logout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent mIntent=new Intent(SettingActivity.this,LoginActivity.class);
startActivity(mIntent);
SettingActivity.this.setResult(RESULT_OK);
SettingActivity.this.finish();
}
}
}