How to change start Activity dynamically?

2019-03-24 16:35发布

I am working on an android app. I want to change Start activity dynamically. i mean when user start app first time then start activity will different and when start second time start activity change.This will skip first two activity and move to third activity .how can i achieve this.

7条回答
贼婆χ
2楼-- · 2019-03-24 17:15

It is not necessary that an Activity must have a layout file. You can have a condition check in your launcher activity and redirect to other activity based on the condition. (The transition from launcher activity to condition activity will not be visible though).

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent;
if (condition) {
   intent = new Intent(this, FirstClass.class);
} else {
   intent = new Intent(this, SecondClass.class);
}
startActivity(intent);
finish();
// note we never called setContentView()
}

Other Activity (FirstClass / SecondClass ):

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
查看更多
登录 后发表回答