启动和主要活动错误

时间:2013-04-15 06:26:16

标签: android

有人可以帮忙。在启动活动之后,主要活动没有打开。但是,如果我输入任何其他意图过滤器名称,它的工作原理不是主要活动。提前谢谢!

SPLASH ACTIVITY:

package com.hellhog.tfreqpro;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class Splash extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.splash);

    MediaPlayer mp = MediaPlayer.create(Splash.this, R.raw.smusic);
    mp.start();

    Thread pro = new Thread(){
        public void run(){
            try{
                sleep(6000);
            }catch (InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent yo = new Intent ("android.intent.action2.MAINACTIVITY");
                startActivity(yo);
            }
        }
    };

    pro.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

}

主要活动:

package com.hellhog.tfreqpro;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class MainActivity extends Activity{

Button a, c;
Intent b, d;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);

    a= (Button) findViewById(R.id.tacan);
    c= (Button) findViewById(R.id.flp);

    a.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            b = new Intent ("android.intent.action.CONVERTER");
            startActivity(b);
        }
    });

    c.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            d = new Intent ("android.intent.action.NEWFLP");
            startActivity(d);
        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

清单:

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

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="10" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.hellhog.tfreqpro.Splash"
        android:label="@string/app_name"
        android:screenOrientation="landscape" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.hellhog.tfreqpro.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action2.MAINACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.hellhog.tfreqpro.Converter"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.CONVERTER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.hellhog.tfreqpro.Flightplan"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.FLIGHTPLAN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.hellhog.tfreqpro.NewFLP"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.NEWFLP" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>        
</application>

</manifest> 

3 个答案:

答案 0 :(得分:2)

在你的Splash Activity中尝试这个..

 Intent yo = new Intent (Splash.this, MainActivity.class);
        startActivity(yo);

在您的清单文件中

<activity
    android:name="com.hellhog.tfreqpro.MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait" >
    <intent-filter>
        <action android:name="android.intent.action2.MAINACTIVITY" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

删除以下意图过滤器

 <intent-filter>
        <action android:name="android.intent.action2.MAINACTIVITY" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>

答案 1 :(得分:1)

这对我来说非常有用!

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  // Removes notification bar

    setContentView(R.layout.splashscreen);

    // Start timer and launch main activity
    IntentLauncher launcher = new IntentLauncher();
    launcher.start();
}

private class IntentLauncher extends Thread {

    @Override
    /**
     * Sleep for some time and than start new activity.
     */
    public void run() {
        try {
            // Sleeping
            Thread.sleep(SLEEP_TIME*1000);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }

        // Start main activity
        Intent intent = new Intent(SplashActivity.this,FullscreenActivity.class);
        SplashActivity.this.startActivity(intent);
        SplashActivity.this.finish();
    }
}

答案 2 :(得分:1)

尝试使用以下代码..

 public class SplashScreenextends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splashscreen);
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        public void run() {
            // TODO Auto-generated method stub
            finish();
            Intent menu = new Intent(getBaseContext(), MainActivity.class);
            startActivity(menu);
        }
    }, 3000);
}

}

它会将你的SplashScreen设置为3秒,然后开始你的主动作或你想要开始的任何活动。它可以帮助你..