Skip to content

Instantly share code, notes, and snippets.

@li2
Last active March 20, 2018 11:27
Show Gist options
  • Save li2/368e98b3159284d529b159983ba924f2 to your computer and use it in GitHub Desktop.
Save li2/368e98b3159284d529b159983ba924f2 to your computer and use it in GitHub Desktop.
[如何避免在切换 activity 时黑屏?而在 service 中 start activity 无法调用 overridePendingTransition] #tags: android-activity
weiyiWorkCell:DVR weiyi$ git diff
diff --git a/app/src/main/java/com/magellan/dvr/activity/WarningsActivity.java b/app/src/main/java/com/magellan/dvr/activity/WarningsActivity.java
index 63b8869..7813fb5 100644
--- a/app/src/main/java/com/magellan/dvr/activity/WarningsActivity.java
+++ b/app/src/main/java/com/magellan/dvr/activity/WarningsActivity.java
@@ -47,6 +47,7 @@ public class WarningsActivity extends Activity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ getWindow().setWindowAnimations(0);
Intent intent = getIntent();
@@ -142,6 +143,7 @@ public class WarningsActivity extends Activity {
Intent intent = new Intent(context, WarningsActivity.class);
intent.putExtra(WarningsActivity.EXTRA_WARNING_TYPE, type);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
if (type == WarningType.SDCARD_EJECTED || type == WarningType.SDCARD_FULL
|| type == WarningType.SDCARD_MEDIA_ERROR || type == WarningType.SDCARD_NO_INSERTED) {
diff --git a/app/src/main/java/com/magellan/dvr/service/DvrService.java b/app/src/main/java/com/magellan/dvr/service/DvrService.java
index 98ef946..a02977d 100644
--- a/app/src/main/java/com/magellan/dvr/service/DvrService.java
+++ b/app/src/main/java/com/magellan/dvr/service/DvrService.java
@@ -596,7 +596,8 @@ public class DvrService extends Service {
case SDCARD_EJECTED:
NavigationIntent.send(mAppContext, NotifyType.SDCARD_EJECTED);
- startWarningsActivity(WarningType.SDCARD_EJECTED);
+ //startWarningsActivity(WarningType.SDCARD_EJECTED);
+ WarningsActivity.start(mAppContext, WarningType.SDCARD_EJECTED);
break;
case SDCARD_ERROR:
diff --git a/app/src/main/res/values-v14/styles.xml b/app/src/main/res/values-v14/styles.xml
index 713435d..b3777b9 100644
--- a/app/src/main/res/values-v14/styles.xml
+++ b/app/src/main/res/values-v14/styles.xml
@@ -1,5 +1,11 @@
<resources>
- <style name="Dvr.DialogActivity" parent="@android:style/Theme.Holo.Light.Dialog"/>
+ <style name="Dvr.DialogActivity" parent="@android:style/Theme.Holo.Light.Dialog">
+ <item name="android:windowNoTitle">true</item>
+ <item name="android:windowBackground">@android:color/transparent</item>
+ <item name="android:colorBackgroundCacheHint">@null</item>
+ <item name="android:windowIsTranslucent">true</item>
+ <item name="android:windowAnimationStyle">@android:style/Animation</item>
+ </style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment