0

我的应用程序首先InitActivity检查登录状态,LoginActivity然后在继续执行某些逻辑之前进行相应的调用。

我知道我可以使用startAcivityForResult()andonActivityResult()来确保LoginActivity在做之前完成doSomeMainLogic(),但是我的if检查在其中抛出了一条曲线。如果我这样做:

public class InitActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!userIsLoggedIn) {
            Intent intent = new Intent("com.example.myapp.LOGINACTIVITY");
            startActivityForResult(intent,1);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1) {
            if (resultCode == RESULT_OK) {
                doSomeMainLogic();
            }
        }
    }

}

doSomeMainLogic()如果用户已经登录,我该如何开火?

非常感谢。

4

1 回答 1

1
public class InitActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!userIsLoggedIn) {
            Intent intent = new Intent("com.example.myapp.LOGINACTIVITY");
            startActivityForResult(intent,1);
        }
        else {
            doSomeMainLogic();  // this part is added
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1) {
            if (resultCode == RESULT_OK) {
                doSomeMainLogic();
            }
        }
    }

}
于 2013-04-23T20:15:37.840 回答