-1

在一个应用程序中,有 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();

                    }
           }
    }
4

2 回答 2

0

在infinish()的末尾调用。然后移动到 时不会在堆栈中。startActivity(<Your Intent>)ActivityBActivityBActivityC

于 2013-06-26T05:15:36.063 回答
0
startActivity(intent);//start the next activity
finish(); //finish the current activity

在这里找到了一个描述性的讨论

于 2013-06-26T03:48:42.770 回答