我希望在主要活动进入之前有一个闪屏,但我的“主要活动”会自动设置为启动器。我在堆栈溢出帖子和谷歌搜索了很多但我无法找到我的案例的解决方案。下面我发布了我的manifest.xml文件,是的,我知道它已经搞砸了(我尝试了一些东西)。
更新:我根据评论中的建议更新了我的manifest.xml文件,并在尝试解决与其他开发人员测试应用程序期间出现的以下问题之后:
应用程序启动,启动画面的背景图像加载然后应用程序崩溃并关闭(有时甚至是整个AVD /电话)
以下是我得到的两个错误(无论我尝试什么,FunFactsActivity.DEAD都会继续发生)。
<?xml version="1.0" encoding="utf-8"?>
<application
android:name=".FunFactsApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreenActivity" android:theme="@style/SplashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".FunFactsActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
ERROR #1:
11-10 11:42:12.718 16295-16295/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:42:12.729 16295-16295/com.spdesigns.funfacts I/art: Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 1% free, 359MB/363MB, paused 538us total 10.161ms
11-10 11:42:12.729 16295-16295/com.spdesigns.funfacts I/art: Forcing collection of SoftReferences for 354MB allocation
11-10 11:42:12.729 16295-16295/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:42:12.736 16295-16295/com.spdesigns.funfacts I/art: Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 1% free, 359MB/363MB, paused 555us total 7.286ms
11-10 11:42:12.736 16295-16295/com.spdesigns.funfacts W/art: Throwing OutOfMemoryError "Failed to allocate a 372109512 byte allocation with 4194304 free bytes and 24MB until OOM"
11-10 11:42:12.737 16295-16295/com.spdesigns.funfacts D/skia: --- allocation failed for scaled bitmap
11-10 11:42:12.744 16295-16295/com.spdesigns.funfacts D/AndroidRuntime: Shutting down VM
11-10 11:42:12.747 16295-16295/com.spdesigns.funfacts E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.spdesigns.funfacts, PID: 16295
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spdesigns.funfacts/com.spdesigns.funfacts.SplashScreenActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.spdesigns.funfacts.SplashScreenActivity.onCreate(SplashScreenActivity.java:17)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 372109512 byte allocation with 4194304 free bytes and 24MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:620)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1155)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
at android.content.res.Resources.loadDrawable(Resources.java:854)
at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
at android.view.View.<init>(View.java:4175)
at android.view.ViewGroup.<init>(ViewGroup.java:578)
at android.widget.LinearLayout.<init>(LinearLayout.java:211)
11-10 11:42:12.747 16295-16295/com.spdesigns.funfacts E/AndroidRuntime: at android.widget.LinearLayout.<init>(LinearLayout.java:207)
at android.widget.LinearLayout.<init>(LinearLayout.java:203)
... 25 more
ERROR #2(DEAD):
11-10 11:43:09.417 16410-16410/com.spdesigns.funfacts I/art: Not late-enabling -Xcheck:jni (already on)
11-10 11:43:09.418 16410-16410/com.spdesigns.funfacts W/art: Unexpected CPU variant for X86 using defaults: x86
11-10 11:43:09.561 16410-16410/com.spdesigns.funfacts W/System: ClassLoader referenced unknown path: /data/app/com.spdesigns.funfacts-2/lib/x86
11-10 11:43:09.583 16410-16410/com.spdesigns.funfacts I/InstantRun: starting instant run server: is main process
11-10 11:43:09.692 16410-16410/com.spdesigns.funfacts W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
11-10 11:43:11.042 16410-16410/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:43:11.042 16410-16410/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:43:11.046 16410-16410/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:43:11.052 16410-16410/com.spdesigns.funfacts I/art: Alloc partial concurrent mark sweep GC freed 99(8KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 359MB/363MB, paused 552us total 5.888ms
11-10 11:43:11.052 16410-16410/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:43:11.060 16410-16410/com.spdesigns.funfacts I/art: Alloc concurrent mark sweep GC freed 38(1840B) AllocSpace objects, 0(0B) LOS objects, 1% free, 359MB/363MB, paused 550us total 8.156ms
11-10 11:43:11.060 16410-16410/com.spdesigns.funfacts I/art: Forcing collection of SoftReferences for 354MB allocation
11-10 11:43:11.060 16410-16410/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:43:11.070 16410-16410/com.spdesigns.funfacts I/art: Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 1% free, 359MB/363MB, paused 678us total 9.530ms
11-10 11:43:11.070 16410-16410/com.spdesigns.funfacts W/art: Throwing OutOfMemoryError "Failed to allocate a 372109512 byte allocation with 4194304 free bytes and 24MB until OOM"
11-10 11:43:11.070 16410-16410/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:43:11.071 16410-16410/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:43:11.076 16410-16410/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:43:11.083 16410-16410/com.spdesigns.funfacts I/art: Alloc partial concurrent mark sweep GC freed 6(144B) AllocSpace objects, 0(0B) LOS objects, 1% free, 359MB/363MB, paused 713us total 7.322ms
11-10 11:43:11.083 16410-16410/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:43:11.091 16410-16410/com.spdesigns.funfacts I/art: Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 1% free, 359MB/363MB, paused 546us total 7.309ms
11-10 11:43:11.091 16410-16410/com.spdesigns.funfacts I/art: Forcing collection of SoftReferences for 354MB allocation
11-10 11:43:11.091 16410-16410/com.spdesigns.funfacts I/art: Starting a blocking GC Alloc
11-10 11:43:11.100 16410-16410/com.spdesigns.funfacts I/art: Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 1% free, 359MB/363MB, paused 744us total 8.983ms
11-10 11:43:11.100 16410-16410/com.spdesigns.funfacts W/art: Throwing OutOfMemoryError "Failed to allocate a 372109512 byte allocation with 4194304 free bytes and 24MB until OOM"
11-10 11:43:11.100 16410-16410/com.spdesigns.funfacts D/skia: --- allocation failed for scaled bitmap
11-10 11:43:11.104 16410-16410/com.spdesigns.funfacts D/AndroidRuntime: Shutting down VM
11-10 11:43:11.105 16410-16410/com.spdesigns.funfacts E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.spdesigns.funfacts, PID: 16410
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spdesigns.funfacts/com.spdesigns.funfacts.SplashScreenActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.spdesigns.funfacts.SplashScreenActivity.onCreate(SplashScreenActivity.java:17)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 372109512 byte allocation with 4194304 free bytes and 24MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:620)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:455)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1155)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571)
at android.content.res.Resources.loadDrawable(Resources.java:854)
at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
at android.view.View.<init>(View.java:4175)
at android.view.ViewGroup.<init>(ViewGroup.java:578)
at android.widget.LinearLayout.<init>(LinearLayout.java:211)
11-10 11:43:11.105 16410-16410/com.spdesigns.funfacts E/AndroidRuntime: at android.widget.LinearLayout.<init>(LinearLayout.java:207)
at android.widget.LinearLayout.<init>(LinearLayout.java:203)
... 25 more
答案 0 :(得分:2)
删除intent-filter
标记如下,我认为它会起作用
<activity android:name=".FunFactsActivity"></activity>
答案 1 :(得分:1)
您只需要删除<intent-filter ...> ..... </intent-filter>
然后您的AndroidManifest.xml看起来像
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.spdesigns.funfacts">
<application
android:name=".FunFactsApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FunFactsActivity">
</activity>
<activity android:name=".SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
我希望这会对你有所帮助。
答案 2 :(得分:0)
如果要启动,请在清单文件中进行此更改 先启动屏幕
<application
android:name=".FunFactsApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FunFactsActivity">
</activity>
<activity android:name=".SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
答案 3 :(得分:0)
在manifest.xml文件中,只有启动器活动应具有如下标记
<activity android:name=".SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
所有其他活动应如下所示..
<activity
android:name=".ActivityOne/>
<activity
android:name=".ActivityTwo"/>
<activity
android:name=".ActivityN"/>
现在假设您希望稍后将ActivityOne作为启动器活动,那么只需将ActivityOne和SplashScreenActivity相互交换。
答案 4 :(得分:0)
我使用以下AndroidManifest.xml创建了一个示例项目:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.spdesigns.funfacts">
<application
android:name=".FunFactsApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FunFactsActivity">
<intent-filter>
<action android:name="android.intent.action.FunFactsActivity" />
<category android:name="android.intent.category.FunFactsActivity" />
</intent-filter>
</activity>
<activity android:name=".SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- This is needed if you want to launch the splash screen without knowing the default main -->
<!-- you can call it with: -->
<!-- Intent intent = new Intent("com.spdesigns.funfacts.LaunchSplash") -->
<!-- context.startActivity(intent); -->
<intent-filter>
<action android:name="com.spdesigns.funfacts.LaunchSplash"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
Splash屏幕正在作为启动器活动。所以,你的代码中的其他地方可能存在问题。
查看示例项目答案 5 :(得分:0)
你去..
<layer-list>
项。在图层下面添加以下代码。
<item android:drawable="@color/colorPrimaryDark"/>
<item>
<bitmap android:src="@drawable/splash"
android:gravity="center"></bitmap>
</item>
3.编辑你的style.xml。根据您的风格添加以下样式标记。
`<style name="SplashScreenTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background</item>
</style>`
4.创建一个扩展到AppCompatActivity的SplashActivity.java。修改你的onCreate方法,如下所示。
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
finish();
}
5.创建一个名为ClockTimer的活动,该活动将扩展到Application。修改onCreate如下。
@Override
public void onCreate() {
super.onCreate();
SystemClock.sleep(2000);
}
6.最后,您需要修改androidmanifest文件。在android清单文件中进行以下更改。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vishal.golevr.splashscreenapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".ClockTime">
<activity android:name=".SplashActivity" android:theme="@style/SplashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
</application>
</manifest>
答案 6 :(得分:0)
如果要启动,请在清单文件中进行此更改 先启动屏幕
<application
android:largeHeap="true" // for large memory use
android:name=".FunFactsApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FunFactsActivity">
</activity>
<activity android:name=".SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
您有两个选项
2.在你的清单文件中添加这个,然后根据你的错误你正在使用一个大尺寸的图像,并且android无法读取,所以你的应用程序崩溃了内存错误。
android:largeHeap="true"