如果第一次调用onCreate(),是否有可以测试的代码?
例如
if (condition) {
code that runs if the app runs for the first time
}else{
code that runs if activity is started because of configuration changes, orientation changes...
}
答案 0 :(得分:3)
这就是我解决问题的方法,但不知道这是否是正确/唯一的方式
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState == null){
Log.d("SEBA", "onCreate in if");
}else {
Log.d("SEBA", "onCreate in else");
}}