I am using the AlarmManager
to pass a PendingIntent
to my BroadcastReceiver
after, say, 5 minutes. Now, I want to show a DialogFragment
to the user, on top of whatever app the user might be using when the alarm goes off. For example, if the user is using Chrome when the alarm goes off, my DialogFragment
should popup ABOVE the user's Chrome window.
What I am ending up with instead, is the DialogFragment
being shown with a blank activity of my app as the background (as in the following pic)
https://i.stack.imgur.com/Vz9IZ.png
This is the code I am using in my BroadcastReceiver
, to launch an FragmentActivity
first :
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Intent hardReminderIntent = new Intent(context, AlarmHardActivity.class);
hardReminderIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(hardReminderIntent);
}
}
Next, from this activity, I am popping up the DialogFragment
:
public class AlarmHardActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentManager fm = getSupportFragmentManager();
AlarmHardDialog editNameDialog = new AlarmHardDialog();
editNameDialog.show(fm, "fragment_dialog");
//setContentView(R.layout.activity_alarm_hard);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.activity_alarm_hard, menu);
return true;
}
}
My questions :
I could not find a way to call
getSupportFragmentManager
directly from theonReceive
in myBroadcastReceiver
, and thus assumed that the only way to obtain a dialog, would be to first call a 'dummy' activity, that creates the dialog. Is there a better way to do this?Irrespective of whether or not my approach was correct, I expected that since there is no call to
setContentView(..)
in AlarmHardActivity, there would be no UI rendered for it. Is my understanding wrong? I also tried callingsetContentView(..)
and then marking the layout to haveTheme.NoDisplay
andandroid:alpha="0"
, but to no avail.
Any help will be much appreciated. Thanks!