【问题标题】:android.content.ActivityNotFoundException: No Activity found to handle Intent splash screenandroid.content.ActivityNotFoundException:没有找到处理 Intent 闪屏的活动
【发布时间】:2013-03-14 22:04:29
【问题描述】:

我在启动画面后加载新意图时遇到问题。我已经查看了与此异常相关的问题,但他们似乎都在处理诸如 google play 或 google maps 未正确引用之类的问题,这对我来说不是这样。

这些是我看过的相关问题

Not found activity to handle intent?

activity not found to handle intent

no activity found to handle intent

下面是我的清单代码

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.main"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <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=".HomePage"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.HOMEPAGE" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".OrderPlaced"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.ORDERPLACED" />

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

</manifest>

这是类启动的代码

package com.android.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class Splash extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        Thread timer = new Thread(){
            public void run(){
                try{
                    sleep(1000);
                }catch(InterruptedException e) {
                    e.printStackTrace();
                }finally{
                    Intent openStartingPoint = new Intent("com.android.main.HOMEPAGE");
                    startActivity(openStartingPoint);
                }
            }
        };
        timer.start();
    }

    @Override
    protected void onPause() {

        super.onPause();
        finish();
    }


}

这是我在启动画面后尝试加载的类 HomePage

package com.android.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class HomePage extends Activity {
    /** Called when the activity is first created. */


    TextView name;
    EditText editName;
    TextView drinks;
    Spinner drinksSpinner;
    TextView message;
    CheckBox checkbox;
    Button createOrderButton;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        createOrder();
    }

    public void createOrder(){

        createOrderButton = (Button) findViewById(R.id.bCreateOrder);
        createOrderButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                postInformationtoAPI();

            }

            private void postInformationtoAPI() {

                goToOrderCompleted();
            }

            private void goToOrderCompleted() {
                Intent intent = new Intent(HomePage.this , OrderPlaced.class);
                HomePage.this.startActivity(intent);
                Log.i("onClick", "trying to start new activity to change layout");
            }
        });

    }
}

加载启动画面后应用程序强制退出并给出以下异常

03-14 22:32:33.553: E/AndroidRuntime(3166): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.main.HOMEPAGE }

对此的任何帮助将不胜感激

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    你必须区分 Intent 的构造函数,

     Intent openStartingPoint = new Intent("com.android.main.HOMEPAGE");
    

    假设com.android.main.HOMEPAGEIntent 的动作过滤器。这在您的应用程序的 android manifest.xml 文件中不可用。你有

    &lt;action android:name="android.intent.action.HOMEPAGE" /&gt;

    应该是,

    &lt;action android:name="com.android.main.HOMEPAGE" /&gt;

    只需更改它,

    Intent openStartingPoint = new Intent(Splash.this, HOMEPAGE.class);
    

    【讨论】:

      【解决方案2】:
              <activity
              android:label="@string/app_name"
              android:name=".SplashScreen"
              android:screenOrientation="landscape"
              android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
              <intent-filter >
                  <action android:name="android.intent.action.MAIN" />
      
                  <category android:name="android.intent.category.LAUNCHER" />
              </intent-filter>
          </activity>
          <activity
              android:name="com.android.main.HOMEPAGE"
              android:screenOrientation="landscape"
              android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
              <intent-filter >
                  <action android:name="com.android.main.HOMEPAGE" />
      
                  <category android:name="android.intent.category.DEFAULT" />
              </intent-filter>
          </activity>
      

      我还有一个计时器任务来显示启动画面

      public class SplashScreen extends Activity{
      
      Timer splashTimer;
      SplashTimerHandler splashTimerHandler;
      
      private boolean applicationPaused=false;
      
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
      
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
      
          setContentView(R.layout.main);
      
          this.setSplash();
      
      
      }
      
      private void setSplash() 
      {
          this.splashTimerHandler=new SplashTimerHandler();
          this.splashTimer=new Timer();
      
          this.splashTimer.schedule(this.splashTimerHandler, 0, 1000);
      
      }
      
      @Override
      public void onPause()
      {
          super.onPause();
          this.applicationPaused=true;
          this.closeSplashTimer();
      }
      
      @Override
      public void onResume()
      {
          super.onResume();
      
          if(this.applicationPaused)
          {
              this.applicationPaused=false;
              this.closeSplashTimer();
              this.setSplash();
          }
      }
      
      public class SplashTimerHandler extends TimerTask{
      
          int splashTimerCounter=0;
          @Override
          public void run()
          {
              splashTimerCounter++;
              if(splashTimerCounter>2)
              {
                  runOnUiThread(splashTimeOver);
              }       
          }
      
          private Runnable splashTimeOver=new Runnable() {
      
              @Override
              public void run()
              {
                  closeSplashTimer();
                  startHomeScreen();
              }
          };      
      }
      
      protected void closeSplashTimer() 
      {
          if(this.splashTimer!=null)
          {
              this.splashTimer.cancel();
              this.splashTimer=null;
          }
      
      }
      
      private void startHomeScreen() 
      {
          this.closeSplashScreen();
          startActivity(new Intent("com.android.main.HOMEPAGE"));
      
      }
      
      private void closeSplashScreen()
      {
          this.closeSplashTimer();
          this.finish();
      
      }
      
      @Override
      public boolean onKeyDown(int keycode, KeyEvent event)
      {
          if(keycode==KeyEvent.KEYCODE_BACK)
          {
              this.closeSplashScreen();
          }
          return true;
      }   
      }
      

      【讨论】:

      • 非常感谢关于启动画面的建议,这只是一般处理启动画面的更好方法吗?
      猜你喜欢
      • 1970-01-01
      • 2015-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      • 2016-02-01
      • 2022-11-04
      • 2021-11-24
      相关资源
      最近更新 更多