0

I use firebird cloud messaging to receive data in the background, then a dialog (new Activity with Theme.AppCompat.Dialog as style) will appear. My problem is that the surface of the MainActivity is displayed every time in the background. Is it possible to hide MainActivity without terminating it? Someone has perhaps an idea?

When i set in the Manifest at the MainActivity the value android:noHistory="true" i looks good, but the notification is then in the app history. this looks bad

I mean when the activity is in Background that the MainActivity is still visible

Example Picture

BhalchandraSW
  • 714
  • 5
  • 13
plex88
  • 53
  • 5
  • set background color in style by defying it in style.xml – Keyur Thumar May 31 '17 at 14:07
  • Thanks for your reply but the MainActivity still opens in background. It should stay in the background. – plex88 May 31 '17 at 14:13
  • offcourse mainactivity will be in the background. – Keyur Thumar May 31 '17 at 16:38
  • Do not have my pc atm but did something similar (somewhat like the popup some sms applications generate) with a transparent background. Mine shows on top of home or lock screen if application is in background. Is that what you are looking for? – cYrixmorten Jun 02 '17 at 17:08

2 Answers2

0

As you are using an Activity as a dialog, your MainActivity remains in the Activity Stack in a paused state. However, even if you make the Dialog Activity full-screen, it is not guaranteed that MainActivity will be kept alive. The OS can kill the activity anytime if it needs memory for other processes. This is stated on the Activity reference.

Instead you could try one of these alternative solutions:

  1. Use a DialogFragment instead of a new Activity
  2. Use regular Fragments, adding the fragment at runtime, allowing the user to switch between the dialog Fragment and the Main fragment.
  3. Use a FrameLayout, to show/hide the dialog UI inside the same Main Activity layout.
  • Thanks for your reply, but i was not able to start the DialogFragment from the Service class because is have no Access to the Displaymanager. This seems to work only from an Activity – plex88 Jun 02 '17 at 15:11
  • You didn't mention a Service class before. If you mean an Android Service, then what's left for you is to [communicate between the Service and the Activity](https://stackoverflow.com/questions/36525508/communication-between-android-services-and-activities) to trigger the display of the dialog. – Paul Estrada Jun 08 '17 at 16:24
0

I think are looking for this method

    /* When {@link #FLAG_DIM_BEHIND} is set, this is the amount of dimming
     * to apply.  Range is from 1.0 for completely opaque to 0.0 for no
     * dim.
     */

dialog.getWindow().getAttributes().dimAmount = 1f;

Reyansh Mishra
  • 1,879
  • 1
  • 14
  • 26