2013-04-12 29 views
0

我做了我的第一個應用程序,它仍然在模擬器上。所以在測試第二個的時候,我運行它。啓動畫面是它的工作,然後而不是去我正在測試的應用程序的主要活動,應用程序退出,並出現一條消息說,通過選擇我要測試的第一個應用程序或第二個應用程序來完成操作。那麼,我該如何避免這種情況,或者讓應用程序不給用戶那個選項?2個應用程序之間的衝突

編輯:

APP 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> 

濺射屏幕CODE:

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(); 
} 



} 

APP 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(); 
} 



    } 
+0

需要更多信息。 – Zyerah

+0

改變兩個活動的包... –

+0

好像什麼? – WhiplashOne

回答

1

這樣做的原因是雙方你的應用程序是不同的(不同的包名的意思),雖然你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.intentMainActivity註冊的意圖過濾 當你觸發一個意圖,爲處理這一意圖Android將做intent-resoltuion,給你的選項所有可以處理該意圖的應用程序,這就是爲什麼你要獲得應用程序選擇器對話框。