Question

I would like to trigger showing a dialog X seconds after something happens in an activity (resumed, button clicked, etc.)

  • What are my options? (e.g. Thread, AsyncTask, Handler)
  • Are there special things to note for these options? e.g. do I need to check if the activity is still active?
Was it helpful?

Solution

use handler.postDelayed(runnable, delayedms);

this is one of the methods, you can also use AlaramManager.

For AlaramManager your activity need not be active. and handler it should be.

OTHER TIPS

One option I considered: instead of attaching a dialog to an existing view, I can create a transparent view (with <activity android:theme="@android:style/Theme.Translucent.NoTitleBar" as mentioned here) and have it create a dialog.

This is nice since I can create this activity with a delayed intent.

I need to make sure to call finish() when the dialog is closed.

I'm not sure how to have this happen only if the original activity is still active.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top