I have a widget which launches to a particular page based on the various widget buttons pressed. It works fine when I have the app in-memory (i.e. from deploy (run / debug), however when I force stop the app, the widget no longer functions properly.
When the app has been force stopped, the first click of the widget works properly, and the onCreate for the corresponding Activity is called. Then, when the home key is pressed, and a different widget button is pressed, the onRestart method of the previous widget Activity is called.
It is odd, b/c the log messages do not appear, and since the debugger cannot be connected, it's been rather difficult to test. Is there anything in particular that I'm doing wrong?
The flow is --> WidgetDispatchActivity (handle true widget destination) --> ViewActivity> --> further branch (DetailViewActivity
in below example)
onUpdate
for widget:
onUpdate(){
...
Intent viewIntent = new Intent(context, WidgetDispatchActivity.class);
viewIntent.putExtra("launch", WidgetInfo.VIEW_ACTIVITY);
PendingIntent viewPendIntent = PendingIntent.getActivity(context, 2, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
...
}
WidgetDispatchActivity's onCreate
:
Bundle b = getIntent().getExtras();
if (b != null && b.isEmpty()){
Log.i(LOG_TAG, "EMPTY BUNDLE ON WIDGET!");
}else{
Log.i(LOG_TAG, "WIDGET BUNDLE HAS ITEMS!");
}
String destination = null;
if (b != null && b.containsKey("launch")){
destination = b.getString("launch");
Log.i(LOG_TAG, "WIDGET ITEM FROM BUNDLE WAS: " + destination);
}
else{
Log.i(LOG_TAG, " \"launch\" item was not inside bundle!");
}
if(destination != null) {
Log.i(LOG_TAG, "PendingIntent received from widget!");
Intent goTo = new Intent(this, ViewActivity.class);
...
}
}
LogCat
10-10 20:38:00.935: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher }
10-10 20:38:00.956: INFO/DetailViewActivity(1154): ONPAUSE
10-10 20:38:00.975: WARN/InputManagerService(58): Ignoring hideSoftInput of: com.android.internal.view.IInputMethodClient$Stub$Proxy@450366d0
10-10 20:38:02.545: INFO/ActivityManager(58): Starting activity: Intent { flg=0x10000000 cmp=com.starbucks.mobilecard/com.xxx.xxx.widget.WidgetDispatchActivity bnds=[198,298][224,321] (has extras) }
10-10 20:38:02.585: INFO/ViewActivity(1154): ONRESTART
10-10 20:38:02.585: INFO/ViewActivity(1154): WIDGET LAUNCH:: == false
ViewActivity onRestart:
protected void onRestart(){
super.onRestart();
Log.i(LOG_TAG,"ONRESTART");
Log.i(LOG_TAG,"WIDGET LAUNCH:: == " + WidgetInfo.getInstance().wasLaunchedFromWidget());
...
}
AndroidManifest:
<activity android:name="com.xxx.xxx.ui.cards.ViewActivity" android:label="@string/_view_title" android:finishOnTaskLaunch="true" android:clearTaskOnLaunch="true" android:screenOrientation="portrait"/>
<activity android:name="com.xxx.xxx.widget.WidgetDispatchActivity" android:label="@string/widget_dispatch_title" android:finishOnTaskLaunch="true"/>