finishActivity(int requestCode)的作用

原创
2017/04/19 16:41
阅读数 2.7K

finishActivity(int requestCode) 当我们在activity中调用finishActivity(int requestCode) 后 并不是关闭当前的activity而是关闭 你用startActivityForResult(intent,code);启动那个activity。注意requestCode必须填写和code一致

public class MainActivity extends AppCompatActivity {
    private final int code=12;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Intent intent=new Intent(this,Main2Activity.class);
        startActivityForResult(intent,code);
        EventBus.getDefault().register(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void newOrder(TestEvent event){
        finishActivity(code);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.e("TAG","onActivityResult");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }




public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
    }

    public void test(View view){
        TestEvent event=new TestEvent();
        EventBus.getDefault().post(event);

    }
}


展开阅读全文
打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部