【问题标题】:Splash screen crash when change in android manifest更改 android manifest 时闪屏崩溃
【发布时间】:2023-03-09 02:45:01
【问题描述】:

我的启动画面 (splash.java) 工作正常,当我在 Android Manifest 中调用它 Launcher 时它会显示 5 秒,但是当我将它修复为Default 在 Android Manifest 中并通过 List Activity (Menu.java) 运行它,它运行 5 秒然后而不是返回到 Menu.java 它会因运行时错误而崩溃。 我希望它显示 5 秒,然后返回 menu.java。

它在 5 秒内无法运行但应用程序在 5 秒后运行时崩溃的清单(不幸的是,您的应用程序已停止)

<activity
    android:name=".Menu"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name=".splash"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="com.example.hello.SPLASH" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

这个splash.java

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity2);
        tone = MediaPlayer.create(splash.this, R.raw.songg);
        tone.start();
        Thread haai = new Thread()
        {
            public void run()
            {
                try
                {
                    sleep(5000);
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
                finally 
                {
                    Intent first = new Intent("com.example.hello.Menu");
                    startActivity(first);
                }
            }       
        };
        haai.start();
    }

错误日志:

E/AndroidRuntime(25707): FATAL EXCEPTION: Thread-30562
E/AndroidRuntime(25707): Process: com.example.hello, PID: 25707
E/AndroidRuntime(25707): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.hello.Menu }
E/AndroidRuntime(25707):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1672)
E/AndroidRuntime(25707):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1442)
E/AndroidRuntime(25707):    at android.app.Activity.startActivityForResult(Activity.java:3511)
E/AndroidRuntime(25707):    at android.app.Activity.startActivityForResult(Activity.java:3472)
E/AndroidRuntime(25707):    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
E/AndroidRuntime(25707):    at android.app.Activity.startActivity(Activity.java:3714)
E/AndroidRuntime(25707):    at android.app.Activity.startActivity(Activity.java:3682)
E/AndroidRuntime(25707):    at com.example.hello.splash$1.run(splash.java:36)

我对自己的答案不满意,因为我正处于学习阶段,所以等待更好的答案并解释其工作和问题。

【问题讨论】:

  • 能否贴出错误日志
  • 我更新了我的错误日志

标签: android android-intent android-manifest


【解决方案1】:

ActivityNotFoundException: 否

因为在清单中未找到带有com.example.hello.MENU 操作的活动。

要解决问题,请对Menu 活动使用com.example.hello.MENU 操作字符串。喜欢:

<activity
    android:name=".Menu"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="com.example.hello.MENU" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

或者您可以使用目标 Activity 类名启动 Activity:

Intent intent=new Intent (splash.this,Menu.class);
splash.this.startActivity(intent);

【讨论】:

  • 我按照您的指导更改了意图过滤器并将 &lt;action android:name="android.intent.action.MAIN" /&gt; 更改为 &lt;action android:name="com.example.hello.MENU" /&gt; 但现在它甚至没有显示 apk ,第二部分在 new 之后缺少类
  • 如果我将 .splash 作为主启动器,为什么它没有显示问题
  • @ARG:从菜单活动标签中删除 &lt;category android:name="android.intent.category.LAUNCHER"
  • 然后应用程序甚至没有打开,应该是启动器然后
  • @ARG:在android:name=".splash"中添加&lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
【解决方案2】:

问题出在清单中,您设置了活动名称 .Menu,而在 java 代码中,您将其设置为 MENU(大写)。

<activity
    android:name=".Menu" <---- activity name as .Menu
    android:label="@string/app_name" >

在java代码中为:

Intent first = new Intent("com.example.hello.MENU")<---.MENU- its all uppercase

在java代码中改变它来解决你的问题:

Intent first = new Intent("com.example.hello.Menu");
startActivity(first);

【讨论】:

  • 同样的错误,不幸的是你的应用程序已经停止,当启动屏幕在 5 秒后完成时
  • 发布新的错误日志,在此之前尝试将&lt;action android:name="com.example.hello.SPLASH" /&gt; 更改为&lt;action android:name="com.example.hello.splash" /&gt;
  • 错误在于找到 .menu , .splash 工作正常,当我将 .splash 作为 MAIN LAUNCHER 时应用程序不会中断,我尝试了上面将 SPLASH 更改为 splash 但它不起作用
  • 您可能没有在 java 代码或 AndroidManifest.xml 中将活动名称更正为 .Menu,如上所述
  • 正如我所说,如果我将 .splash 作为启动器作为 .Menu 作为默认值,它会起作用
【解决方案3】:

我找到了答案,它很简单,但我使用了另一种方式,但我仍然不明白为什么当 .splash 制作为 MainLAUNCHER 时程序运行良好,但是当将 .Menu 制作为 @ 时987654325@ 和 LAUNCHER 程序运行,但是当我从菜单列表中选择启动时,它运行了 5 秒钟,然后它没有再次返回菜单,而是因运行时错误而崩溃。我将.splash 代码更改为以下代码,它可以工作,但由于我是 android 新手,我不知道为什么最后一种方法不起作用。

public void run()
            {
                try
                {
                    sleep(5000);
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
                finally 
                {
                    try
                    {
                    Class ourclass = Class.forName("com.example.hello.Menu");
                    Intent myclass = new Intent(splash.this , ourclass);
                    startActivity(myclass);
                    }
                    catch(ClassNotFoundException e)
                    {
                        e.printStackTrace();
                    }

                }
            }       

我没有对 Android Manifest 进行任何更改

【讨论】:

  • 那么,上面的代码使用Menu 作为Launcher + MainSplash 作为Default?
  • 是的,但为什么它不能以另一种方式工作,在这种方法中有时它看起来就像菜单屏幕出现两次,就像你必须按两次后退按钮一样,但为什么不是其他方法,有什么区别
【解决方案4】:

问题是您声明的意图操作是 .SPLASH 但您创建的操作是 .MENU
改变

Intent first = new Intent("com.example.hello.MENU");
                   startActivity(first);

Intent first = new Intent("com.example.hello.SPALSH");
                   startActivity(first);

或者像这样改变你的清单

<activity
        android:name=".splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Menu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.hello.MENU" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

【讨论】:

  • 我做了但还是崩溃问题
  • 对不起,我错了 android:name 请看我的编辑
  • 我不希望当我的应用程序启动时出现闪屏,我希望该菜单首先出现
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-04
  • 1970-01-01
  • 2015-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多