如果应用程序从后台恢复,但总是调用onResume()
,则我需要回调。
我通过以下方式打开活动:
Intent i = new Intent(this, Spedizione.class);
i.putExtra("codice", result.getText());
startActivity(i);
onResume代码:
@Override
protected void onResume() {
super.onResume();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
}
当打开Activity
onResume()
时,总是调用AlertDialog,不仅当应用从后台恢复时,为什么?仅当从后台重新打开应用程序时,我才需要回调。
最佳答案
OnResume()是一个活动生命周期方法,每次都会调用它。您可以通过将调用放在onRestart()上来处理条件,或者维护一个布尔值以检查是否使用firstTimeCall。
关于java - 仅当恢复 Activity 时才onResume(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46857754/