简体   繁体   中英

onResume() only if Resume Activity

I need callback if application resume from background but onResume() is called always Activity start.

I open a Activity with:

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

onResume code:

    @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?

I just need callback only if application is reopen from background.

OnResume() is an activity lifecycle method which gets called every time. You can handle your condition by putting your call on onRestart() or maintain a boolean to check firstTimeCall or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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