Reputation: 23
How do i show an AlertDialog from receiver class. My receiver class receives by time of my Alarm using AlarmManager
. And, my alertdialog can show if my application is not opened also.
How can i achieve this? Thanks.
Upvotes: 1
Views: 986
Reputation: 33996
There is not possible to create AlertDialog from Broadcast Receiver. But there is one way to accomplish this task.
So you code will looks like below
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, yourDialogActivity.class);
i .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
Upvotes: 2
Reputation: 24476
Yes, you can do like this. Just start one activity class from your receiver using Intent
and in that activity class just use the code from this Blog
Change that class with whatever you needs for AlertDialog. This will display the when your application closed also. Hope this helps you.
Upvotes: 0