Stephen
2010-08-06 10:16:09 UTC
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
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
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