From 1cb4d479f17b1c0cddb866aab4c9602d049902da Mon Sep 17 00:00:00 2001 From: Michael Kaiser Date: Tue, 8 Apr 2014 16:33:21 +0200 Subject: [PATCH] Finish activity before restarting it The current activity needs to be finished before calling startActivity. Otherwise, activities with launchMode singleTask (ConversationListActivity) will receive a new Intent instead of getting restarted. And in response to the new Intent, they will run onResume once again and trigger a second restart. Fixes #1292 --- .../securesms/util/DynamicLanguage.java | 15 ++++++--------- .../securesms/util/DynamicTheme.java | 18 +++++++----------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/org/thoughtcrime/securesms/util/DynamicLanguage.java b/src/org/thoughtcrime/securesms/util/DynamicLanguage.java index b3702149a8..a2ad2b9fae 100644 --- a/src/org/thoughtcrime/securesms/util/DynamicLanguage.java +++ b/src/org/thoughtcrime/securesms/util/DynamicLanguage.java @@ -21,16 +21,13 @@ public class DynamicLanguage { public void onResume(Activity activity) { if (!currentLocale.equals(getSelectedLocale(activity))) { - Intent intent = activity.getIntent(); - intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); - - activity.startActivity(intent); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + activity.recreate(); + } else { + Intent intent = activity.getIntent(); + activity.finish(); OverridePendingTransition.invoke(activity); - } - - activity.finish(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { + activity.startActivity(intent); OverridePendingTransition.invoke(activity); } } diff --git a/src/org/thoughtcrime/securesms/util/DynamicTheme.java b/src/org/thoughtcrime/securesms/util/DynamicTheme.java index 2a1e3d0bce..f7646b9072 100644 --- a/src/org/thoughtcrime/securesms/util/DynamicTheme.java +++ b/src/org/thoughtcrime/securesms/util/DynamicTheme.java @@ -21,19 +21,15 @@ public class DynamicTheme { public void onResume(Activity activity) { if (currentTheme != getSelectedTheme(activity)) { - Intent intent = activity.getIntent(); - intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); - - activity.startActivity(intent); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + activity.recreate(); + } else { + Intent intent = activity.getIntent(); + activity.finish(); + OverridePendingTransition.invoke(activity); + activity.startActivity(intent); OverridePendingTransition.invoke(activity); } - - activity.finish(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { - OverridePendingTransition.invoke(activity); - } - } }