0

我制作了我的第一个应用程序,它仍然在模拟器上。所以在测试第二个时,我运行它。启动画面完成了它的工作,然后不是进入我正在测试的应用程序的主要活动,应用程序退出并出现一条消息说,通过选择我正在测试的第一个应用程序或第二个应用程序来完成操作. 那么如何避免这种情况或使应用程序不给用户该选项呢?

编辑:

应用程序 1:

显现:

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >      
    <activity 
    android:name="com.google.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >        
    </activity>

    <activity
        android:name="com.hellhog.tfreq.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.tfreq.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAINACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

闪屏代码:

package com.hellhog.tfreq;

import com.hellhog.tfreq.R;

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 hog = MediaPlayer.create(Splash.this, R.raw.smusic);
    hog.start();

    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(6000); 
            }catch (InterruptedException e){
                e.printStackTrace(); 
            }finally{
                Intent openSplashLayout = new Intent("android.intent.action.MAINACTIVITY"); 
                startActivity(openSplashLayout); 
            }
        }
    };
    timer.start();  
}

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



 }

应用程序 2:清单:

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

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.hellhogone.multitools.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.hellhogone.multitools.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAINACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.hellhogone.multitools.FlashLight"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.FLASHLIGHT" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.hellhogone.multitools.Mirror"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MIRROR" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

启动画面:

package com.hellhogone.multitools;

import com.hellhogone.multitools.R;

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

public class Splash extends Activity{

@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.splash);

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

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

    timer.start(); 
}

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



    }
4

1 回答 1

2

这样做的原因是您的应用程序不同(意味着具有不同的包名称),而在两个应用程序的 Androidmanifest 文件中,您为 MainActivity 指定了相同的意图过滤器。请考虑在两个应用程序中添加不同的意图过滤器。

    <activity android:name="MainActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="com.example.yourcustom.intent"/>
        </intent-filter>
    </activity>

如上例com.example.yourcustom.intent是为MainActivity注册的意图过滤器 每当您触发意图时,为了处理该意图,Android 将执行意图解析并为您提供所有可以处理该意图的应用程序的选项,这就是您的原因获取应用程序选择器对话框。

于 2013-04-12T06:06:07.173 回答