korax
korax

Reputation: 25

Open a PopUpWindow from an AppWidget

As it doesn't appear to be possible to put an EditText in an AppWidget, I would like to open a PopUpWindow with an EditText when I click on it.

I know how to open an Activity from an AppWidget and I also know how open a PopUpWindow from an Activity. I don't, however, know how to open a PopUpWindow from an AppWidget. I've looked into many classes in the javadoc (Intent, RemoteViews, PendingIntent, etc.), but I can't find how to start this PopUpWindow. Any help would be appreciated.

Upvotes: 2

Views: 398

Answers (2)

rdmc
rdmc

Reputation: 21

You could have the appWidget open an activity which then shows a dialog fragment, or make the activity look like a dialog using a dialog style.

Upvotes: 0

hasanghaforian
hasanghaforian

Reputation: 14022

You know that AppWidgetProvider is a BroadcastReceiver.Android Doc says:

A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active.

This has important repercussions to what you can do in an onReceive(Context, Intent) implementation: anything that requires asynchronous operation is not available, because you will need to return from the function to handle the asynchronous operation, but at that point the BroadcastReceiver is no longer active and thus the system is free to kill its process before the asynchronous operation completes.

In particular, you may not show a dialog or bind to a service from within a BroadcastReceiver. For the former, you should instead use the NotificationManager API. For the latter, you can use Context.startService() to send a command to the service.

It seems you have three ways:

  1. Use a service to show popup(see How to display alert diaolog(popup) from backgroung running service?)
  2. Use notification manager(see AlarmManager never calling onRecieve in AlarmReceiver/BroadcastReceiver).
  3. Create an activity whit dialog theme(so it looks like a popup) and display it when user click your AppWidget.

Upvotes: 1

Related Questions