From 064b30b258993e7f9632fa516a7ef10f949610bb Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Mon, 20 Oct 2014 03:42:13 +0200 Subject: [PATCH] WeatherInformation: remove widget configure from application Otherwise the widget configure activity appears when launching my application instead of the main activity (it is as if Android remembers the last activity) --- .../app/src/main/AndroidManifest.xml | 1 + .../de/example/exampletdd/WidgetIntentService.java | 70 +++++++++++----------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/Android/WeatherInformation/app/src/main/AndroidManifest.xml b/Android/WeatherInformation/app/src/main/AndroidManifest.xml index 342ce75..a628b0b 100644 --- a/Android/WeatherInformation/app/src/main/AndroidManifest.xml +++ b/Android/WeatherInformation/app/src/main/AndroidManifest.xml @@ -81,6 +81,7 @@ diff --git a/Android/WeatherInformation/app/src/main/java/de/example/exampletdd/WidgetIntentService.java b/Android/WeatherInformation/app/src/main/java/de/example/exampletdd/WidgetIntentService.java index f6c3e36..ba6a4fc 100644 --- a/Android/WeatherInformation/app/src/main/java/de/example/exampletdd/WidgetIntentService.java +++ b/Android/WeatherInformation/app/src/main/java/de/example/exampletdd/WidgetIntentService.java @@ -244,28 +244,28 @@ public class WidgetIntentService extends IntentService { final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class); resultIntent.putExtra("actionFromUser", true); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK ); + // resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK ); // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/") ,String.valueOf(appWidgetId)); resultIntent.setData(data); -// final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); -// // Adds the back stack for the Intent (but not the Intent itself) -// stackBuilder.addParentStack(WidgetConfigure.class); -// // Adds the Intent that starts the Activity to the top of the stack -// stackBuilder.addNextIntent(resultIntent); -// final PendingIntent resultPendingIntent = -// stackBuilder.getPendingIntent( -// 0, -// PendingIntent.FLAG_UPDATE_CURRENT -// ); -// remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent); - final PendingIntent resultPendingIntent = PendingIntent.getActivity( - this.getApplicationContext(), - 0, - resultIntent, - PendingIntent.FLAG_UPDATE_CURRENT); - remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent); + final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); + // Adds the back stack for the Intent (but not the Intent itself) + stackBuilder.addParentStack(WidgetConfigure.class); + // Adds the Intent that starts the Activity to the top of the stack + stackBuilder.addNextIntent(resultIntent); + final PendingIntent resultPendingIntent = + stackBuilder.getPendingIntent( + 0, + PendingIntent.FLAG_UPDATE_CURRENT + ); + remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent); +// final PendingIntent resultPendingIntent = PendingIntent.getActivity( +// this.getApplicationContext(), +// 0, +// resultIntent, +// PendingIntent.FLAG_UPDATE_CURRENT); +// remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent); return remoteView; } @@ -277,27 +277,27 @@ public class WidgetIntentService extends IntentService { final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class); resultIntent.putExtra("actionFromUser", true); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK ); +// resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK ); // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/") ,String.valueOf(appWidgetId)); resultIntent.setData(data); -// final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); -// // Adds the back stack for the Intent (but not the Intent itself) -// stackBuilder.addParentStack(WidgetConfigure.class); -// // Adds the Intent that starts the Activity to the top of the stack -// stackBuilder.addNextIntent(resultIntent); -// final PendingIntent resultPendingIntent = -// stackBuilder.getPendingIntent( -// 0, -// PendingIntent.FLAG_UPDATE_CURRENT -// ); - final PendingIntent resultPendingIntent = PendingIntent.getActivity( - this.getApplicationContext(), - 0, - resultIntent, - PendingIntent.FLAG_UPDATE_CURRENT); - remoteView.setOnClickPendingIntent(R.id.weather_appwidget_error, resultPendingIntent); + final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); + // Adds the back stack for the Intent (but not the Intent itself) + stackBuilder.addParentStack(WidgetConfigure.class); + // Adds the Intent that starts the Activity to the top of the stack + stackBuilder.addNextIntent(resultIntent); + final PendingIntent resultPendingIntent = + stackBuilder.getPendingIntent( + 0, + PendingIntent.FLAG_UPDATE_CURRENT + ); +// final PendingIntent resultPendingIntent = PendingIntent.getActivity( +// this.getApplicationContext(), +// 0, +// resultIntent, +// PendingIntent.FLAG_UPDATE_CURRENT); +// remoteView.setOnClickPendingIntent(R.id.weather_appwidget_error, resultPendingIntent); return remoteView; } -- 2.1.4