简体   繁体   English

仅当恢复活动时才onResume()

[英]onResume() only if Resume Activity

I need callback if application resume from background but onResume() is called always Activity start. 如果应用程序从后台恢复,但onResume()始终称为Activity start,则需要回调。

I open a Activity with: 我通过以下方式打开活动:

Intent i = new Intent(this, Spedizione.class);
i.putExtra("codice", result.getText());
 startActivity(i);

onResume code: 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();
    }

When open Activity onResume() always call AlertDialog, not only if app is resume from background, why? 当打开Activity onResume()始终调用AlertDialog,不仅当应用从后台恢复时,为什么?

I just need callback only if application is reopen from background. 仅当从后台重新打开应用程序时,我才需要回调。

OnResume() is an activity lifecycle method which gets called every time. OnResume()是一个活动生命周期方法,每次都会调用它。 You can handle your condition by putting your call on onRestart() or maintain a boolean to check firstTimeCall or not. 您可以通过将调用放在onRestart()上来处理条件,或者维护一个布尔值以检查是否使用firstTimeCall。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM