Discussion:
start AlertDialog from AppWidgetProvider
Stephen
2010-08-06 10:16:09 UTC
Permalink
Anyone know if it is possible to add AlertDialog within a
AppWidgetProvider class?

Here is the code I am working on where I start the AlertDialog on
onEnabled function call.

@Override
public void onEnabled(Context context) {
super.onEnabled(context);
Log.v(TAG,"onEnabledWidget");
AlertDialog.Builder builder = new
AlertDialog.Builder(context).setIcon(
android.R.drawable.ic_dialog_info
).setTitle(R.string.app_name)
.setMessage("This is testing")
.setNeutralButton("Confirm",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
alertNotSmc = builder.create();
alertNotSmc.show();
//runs when all of the first instance of the widget are placed
//on the home screen


}


08-06 18:07:43.938: ERROR/AndroidRuntime(514): Uncaught handler:
thread main exiting due to uncaught exception
08-06 18:07:44.038: ERROR/AndroidRuntime(514):
java.lang.RuntimeException: Unable to start receiver
com.vaka.select.AppSelectWidget: android.view.WindowManager
$BadTokenException: Unable to add window -- token null is not for an
application
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.app.ActivityThread.handleReceiver(ActivityThread.java:2604)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.app.ActivityThread.access$3100(ActivityThread.java:119)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1871)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.os.Handler.dispatchMessage(Handler.java:99)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.os.Looper.loop(Looper.java:123)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.app.ActivityThread.main(ActivityThread.java:4310)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
java.lang.reflect.Method.invokeNative(Native Method)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
java.lang.reflect.Method.invoke(Method.java:521)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
dalvik.system.NativeStart.main(Native Method)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): Caused by:
android.view.WindowManager$BadTokenException: Unable to add window --
token null is not for an application
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.view.ViewRoot.setView(ViewRoot.java:472)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.app.Dialog.show(Dialog.java:239)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
com.vaka.select.AppSelectWidget.onEnabled(AppSelectWidget.java:71)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.appwidget.AppWidgetProvider.onReceive(AppWidgetProvider.java:
73)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
com.vaka.select.AppSelectWidget.onReceive(AppSelectWidget.java:52)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): at
android.app.ActivityThread.handleReceiver(ActivityThread.java:2595)
08-06 18:07:44.038: ERROR/AndroidRuntime(514): ... 10 more
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Mark Murphy
2010-08-06 10:19:24 UTC
Permalink
Post by Stephen
Anyone know if it is possible to add AlertDialog within a
AppWidgetProvider class?
Use a configuration activity if you need a UI when the app widget is
being added:

http://developer.android.com/guide/topics/appwidgets/index.html#Configuring
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Stephen
2010-08-06 10:38:36 UTC
Permalink
Oh, that can start a AlertDialog in Home screen.
I will give it a go. Thx

Regards,
Stephen
Post by Mark Murphy
Post by Stephen
Anyone know if it is possible to add AlertDialog within a
AppWidgetProvider class?
Use a configuration activity if you need a UI when the app widget is
http://developer.android.com/guide/topics/appwidgets/index.html#Confi...
--
Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Stephen
2010-08-09 02:08:55 UTC
Permalink
I see facebook widget can start dialog at anytime. Is it also
configure activity?

If I use the following to my widget.

Intent newReleaseIntent = new
Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
newReleaseIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetId);
PendingIntent pendingRelease = PendingIntent.getActivity(context, 0,
newReleaseIntent, 0);
remoteview.setOnClickPendingIntent(R.id.image1, pendingRelease);

It will create a shortcut icon on the shortcut. But I think facebook
does not is it something do with manifest.xml?
Post by Stephen
Oh, that can start a AlertDialog in Home screen.
I will give it a go. Thx
Regards,
Stephen
Post by Mark Murphy
Post by Stephen
Anyone know if it is possible to add AlertDialog within a
AppWidgetProvider class?
Use a configuration activity if you need a UI when the app widget is
http://developer.android.com/guide/topics/appwidgets/index.html#Confi...
--
Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!- 隱藏被引用文字 -
- 顯示被引用文字 -
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Stephen
2010-08-11 02:05:47 UTC
Permalink
I got the solution. Probably you might already know but if anyone dont
want your started activity display when user long press "home", put
android:excludeFromRecents="true" for the activity.

Otherwise, user might launched wrong activity from the recent list.

Regards,
Stephen
Post by Stephen
I see facebook widget can start dialog at anytime. Is it also
configure activity?
If I use the following to my widget.
Intent newReleaseIntent = new
Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
newReleaseIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetId);
PendingIntent pendingRelease = PendingIntent.getActivity(context, 0,
newReleaseIntent, 0);
remoteview.setOnClickPendingIntent(R.id.image1, pendingRelease);
It will create a shortcut icon on the shortcut. But I think facebook
does not is it something do with manifest.xml?
Post by Stephen
Oh, that can start a AlertDialog in Home screen.
I will give it a go. Thx
Regards,
Stephen
Post by Mark Murphy
Post by Stephen
Anyone know if it is possible to add AlertDialog within a
AppWidgetProvider class?
Use a configuration activity if you need a UI when the app widget is
http://developer.android.com/guide/topics/appwidgets/index.html#Confi...
--
Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!- 隱藏被引用文字 -
- 顯示被引用文字 -- 隱藏被引用文字 -
- 顯示被引用文字 -
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Loading...