启动主题导致重启
Launch theme causing reboot
我想充分利用 "cold start" 时间,展示一个品牌发布主题,正如所描述的那样 in this post。
我遵循了每一步,但在启动应用程序时,仿真器和真实设备都会进行热重启。
我相信这与我在应用程序中使用的 Google Play Services 有关。
我也尝试了 运行 this 项目,它遵循上述 post 并且不包括播放服务,一切都很好,所以它与设备无关。
这是一些代码:
Manifest.xml
<application
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.Launch">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
styles.xml
<style name="AppTheme.Launch" parent="AppTheme" >
<item name="android:windowBackground">@drawable/bg_launch</item>
</style>
bg_launch.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="?android:windowBackground" />
<item>
<bitmap android:src="@drawable/ic_logo"
android:gravity="center" />
</item>
build.gradle(插件版本:2.0.0-alpha6)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.rocca.app"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "0.9"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:gridlayout-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.1.1'
}
MainActivity.java
@Override
protected void onCreate(final Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpGoogleApiClient(); //for IAB
setUpAds();
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:id="@+id/root">
<com.google.android.gms.ads.AdView
android:id="@+id/ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="..." />
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewPager"
android:layout_above="@+id/ad_view"/>
</RelativeLayout>
Logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rocca.ringapp, PID: 5553
java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.hasSystemFeature(ApplicationPackageManager.java:413)
at org.chromium.android_webview.AwSettings.<init>(AwSettings.java:232)
at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:232)
at android.webkit.WebView.<init>(WebView.java:606)
at android.webkit.WebView.<init>(WebView.java:542)
at android.webkit.WebView.<init>(WebView.java:525)
at android.webkit.WebView.<init>(WebView.java:512)
at android.webkit.WebView.<init>(WebView.java:502)
at com.google.android.gms.ads.internal.u.k.<init>(SourceFile:227)
at com.google.android.gms.ads.internal.u.k.a(SourceFile:204)
at com.google.android.gms.ads.internal.u.i.a(SourceFile:52)
at com.google.android.gms.ads.internal.d.a(SourceFile:76)
at com.google.android.gms.ads.internal.n.a(SourceFile:100)
at com.google.android.gms.ads.internal.g.run(SourceFile:196)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.content.pm.IPackageManager$Stub$Proxy.hasSystemFeature(IPackageManager.java:4264)
at android.app.ApplicationPackageManager.hasSystemFeature(ApplicationPackageManager.java:411)
at org.chromium.android_webview.AwSettings.<init>(AwSettings.java:232)
at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:232)
at android.webkit.WebView.<init>(WebView.java:606)
at android.webkit.WebView.<init>(WebView.java:542)
at android.webkit.WebView.<init>(WebView.java:525)
at android.webkit.WebView.<init>(WebView.java:512)
at android.webkit.WebView.<init>(WebView.java:502)
at com.google.android.gms.ads.internal.u.k.<init>(SourceFile:227)
at com.google.android.gms.ads.internal.u.k.a(SourceFile:204)
at com.google.android.gms.ads.internal.u.i.a(SourceFile:52)
at com.google.android.gms.ads.internal.d.a(SourceFile:76)
at com.google.android.gms.ads.internal.n.a(SourceFile:100)
at com.google.android.gms.ads.internal.g.run(SourceFile:196)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
错误发生在 bg_launch.xml,在 android:drawable="?android:windowBackground"
。
正在将 <item>
更改为
<item>
<shape android:shape="rectangle">
<solid android:color="@color/grey_50" />
</shape>
</item>
以某种方式让它发挥作用。
我想充分利用 "cold start" 时间,展示一个品牌发布主题,正如所描述的那样 in this post。 我遵循了每一步,但在启动应用程序时,仿真器和真实设备都会进行热重启。 我相信这与我在应用程序中使用的 Google Play Services 有关。 我也尝试了 运行 this 项目,它遵循上述 post 并且不包括播放服务,一切都很好,所以它与设备无关。 这是一些代码:
Manifest.xml
<application
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.Launch">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
styles.xml
<style name="AppTheme.Launch" parent="AppTheme" >
<item name="android:windowBackground">@drawable/bg_launch</item>
</style>
bg_launch.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="?android:windowBackground" />
<item>
<bitmap android:src="@drawable/ic_logo"
android:gravity="center" />
</item>
build.gradle(插件版本:2.0.0-alpha6)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.rocca.app"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "0.9"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:gridlayout-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.1.1'
}
MainActivity.java
@Override
protected void onCreate(final Bundle savedInstanceState) {
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpGoogleApiClient(); //for IAB
setUpAds();
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:id="@+id/root">
<com.google.android.gms.ads.AdView
android:id="@+id/ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="..." />
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewPager"
android:layout_above="@+id/ad_view"/>
</RelativeLayout>
Logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rocca.ringapp, PID: 5553
java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.hasSystemFeature(ApplicationPackageManager.java:413)
at org.chromium.android_webview.AwSettings.<init>(AwSettings.java:232)
at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:232)
at android.webkit.WebView.<init>(WebView.java:606)
at android.webkit.WebView.<init>(WebView.java:542)
at android.webkit.WebView.<init>(WebView.java:525)
at android.webkit.WebView.<init>(WebView.java:512)
at android.webkit.WebView.<init>(WebView.java:502)
at com.google.android.gms.ads.internal.u.k.<init>(SourceFile:227)
at com.google.android.gms.ads.internal.u.k.a(SourceFile:204)
at com.google.android.gms.ads.internal.u.i.a(SourceFile:52)
at com.google.android.gms.ads.internal.d.a(SourceFile:76)
at com.google.android.gms.ads.internal.n.a(SourceFile:100)
at com.google.android.gms.ads.internal.g.run(SourceFile:196)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.content.pm.IPackageManager$Stub$Proxy.hasSystemFeature(IPackageManager.java:4264)
at android.app.ApplicationPackageManager.hasSystemFeature(ApplicationPackageManager.java:411)
at org.chromium.android_webview.AwSettings.<init>(AwSettings.java:232)
at com.android.webview.chromium.WebViewChromium.init(WebViewChromium.java:232)
at android.webkit.WebView.<init>(WebView.java:606)
at android.webkit.WebView.<init>(WebView.java:542)
at android.webkit.WebView.<init>(WebView.java:525)
at android.webkit.WebView.<init>(WebView.java:512)
at android.webkit.WebView.<init>(WebView.java:502)
at com.google.android.gms.ads.internal.u.k.<init>(SourceFile:227)
at com.google.android.gms.ads.internal.u.k.a(SourceFile:204)
at com.google.android.gms.ads.internal.u.i.a(SourceFile:52)
at com.google.android.gms.ads.internal.d.a(SourceFile:76)
at com.google.android.gms.ads.internal.n.a(SourceFile:100)
at com.google.android.gms.ads.internal.g.run(SourceFile:196)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
错误发生在 bg_launch.xml,在 android:drawable="?android:windowBackground"
。
正在将 <item>
更改为
<item>
<shape android:shape="rectangle">
<solid android:color="@color/grey_50" />
</shape>
</item>
以某种方式让它发挥作用。