From: Gustavo Martin Morcuende Date: Mon, 20 Oct 2014 01:42:13 +0000 (+0200) Subject: WeatherInformation: remove widget configure from application X-Git-Tag: weatherinformation-1.0~95 X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=98ccb49d20e129d2a0d1aab1e545fe9547b37698;p=AndroidWeatherInformation 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) --- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 342ce75..a628b0b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -81,6 +81,7 @@ diff --git a/app/src/main/java/de/example/exampletdd/WidgetIntentService.java b/app/src/main/java/de/example/exampletdd/WidgetIntentService.java index f6c3e36..ba6a4fc 100644 --- a/app/src/main/java/de/example/exampletdd/WidgetIntentService.java +++ b/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; }