How to call recreate()?

后端 未结 3 1155
自闭症患者
自闭症患者 2021-01-01 16:42

I know this is probably extremely simple, but I just can not figure it out.

I\'m trying to reload/recreate an activity after an action. I know I could just use:

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 17:39

    While using the recreate method works by doing

    this.recreate()
    

    It was only added in API level 11. If you want to include more devices you can check the API level and implement both the recreate method as well as

    Intent intent = getIntent();
    finish();
    startActivity(intent);
    

    You can use both by making an if statement like...

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        //Code for recreate
        recreate();
    } else {
        //Code for Intent
        Intent intent = getIntent();
        finish();
        startActivity(intent);
    }
    

提交回复
热议问题