On Android, how do you switch activities programmatically?

前端 未结 8 898
盖世英雄少女心
盖世英雄少女心 2020-12-01 06:29

It seems like every example I can find of switching between activities involves creating an Intent and passing in the context of a View via an OnClickListener associated wit

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 06:33

    You can create intent in the main activity like this

    Intent intent = new Intent(FirstActivity.this, second.class);
    startActivity(intent);
    

    If you are waiting for result from the second then you should use

    StartActivityforresult(intent,request code).

    Request code can be any integer.

提交回复
热议问题