3117

Unexpected behavior when launching a dialog-style activity

I observed from WhatsApp such behaviors: when a new message arrives, WhatsApp will launch a dialog-style activity and such a activity could be cancelled or confirmed by the user.

Therefore, I added a similar dialog-style activity to my app. For test purposes, I also added an alarm manager and an alarm receiver so that this activity will be launched every 10 seconds by the alarm receiver.

The code I used to launch the dialog-style activity is:

Intent dialogIntent = new Intent(MyApplication.sharedApplication, MyDialogStyleActivity.class); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); MyApplication.sharedApplication.startActivity(dialogIntent);

Everything looked fine if my application had not been launched. The dialog activity would show , behind which was the home screen, just like WhatsApp's behavior.

But there was a problem, if my application had been launched and put in the background, and then the alarm triggered the launch of the dialog activity, before the launch of the dialog activity, the main activity of my app would come back to foreground and show as well.

I'm confused, all I want for now is that, even if my application had been launched, when something triggers the dialog-style activity, only this dialog-style activity would show, no main activity or any other un-related activity.

Anyone could help?

Answer1:

Your application maintains an activity stack. So your main activity A and your dialog activity B is represented as A->B in your app's activity stack.

When your app is launched and put to background. When your dialog activity is invoked and brought to the foreground, your main activity A is still live and thus will be shown as well. Maybe you can call "finish()" in A after startActivity(dialogActivity) to make sure A is finished and goes away.

Recommend

  • Border for ContentDialog in Windows Phone 8.1
  • AlertDialog - gap between custom view and title/buttons
  • android Progress dialog -> publishProgress method
  • How to make the switch button center in dialog
  • jquery ui - modal dialog (better way to create content of modal?)
  • Office Dialog API send message to child dialog
  • Angular nested component and reactive forms updating data model
  • C# Simple Event Handler for Setting Alarm
  • How to trigger an alarm only once in Android?
  • Android AlarmClock search by label
  • applicationWillTerminate not called
  • AnalyticsReceiver in Google Analytics Tracking
  • Weird UIView coordinate issue
  • How to programmatically dismiss system dialogs like “ would like to access your photos”?
  • What's the best way to have reusable dialog boxes?
  • Gradle Checkstyle Plugin Console Output
  • How to make QToolTip message persistent?
  • How to debug office add-in for mac?
  • Custom partiotioning of JavaDStreamPairRDD
  • Thread Synchronization with IntentService
  • Force iPad app to launch in portrait when landscape is supported
  • onActivityResult() not called after startActivityForResult() with Intent.ACTION_GET_CONTENT
  • How many percent of the tweets does twitter sample API give?
  • Deleting a widget from QTableView
  • Using android opencv apps without downloading opencv sdk manager
  • ConnectivityManager.CONNECTIVITY_ACTION deprecated
  • How to create two column output from a single column
  • Scanner nextInt() and hasNextInt() problems
  • didUpdatePushCredentials not get called
  • ThreadStatic in asynchronous ASP.NET Web API
  • Why use database factory in asp.net mvc?
  • Is it possible to open regedit and navigate to straight to a specific key using process.start?
  • how to avoid repetitive constructor in children
  • SharedPreferences or SQLite Database?
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Saving Changes After In-App Purchase Has Been Purchased
  • print() is showing quotation marks in results
  • Python urlparse: small issue
  • How to install a .deb file on a jailbroken iphone programmatically?
  • Q promise. Difference between .when and .then
  • Display issues when we change from one jquery mobile page to another in firefox
  • Illegal mix of collations for operation for date/time comparison
  • Deselecting radio buttons while keeping the View Model in synch
  • Java applet as stand-alone Windows application?
  • JSON with duplicate key names losing information when parsed
  • Jquery - Jquery Wysiwyg return html as a string
  • retrieve vertices with no linked edge in arangodb
  • WPF Applying a trigger on binding failure
  • Suggestions to manage Login/Logout transitions