[英]Conflicts between 2 apps
I made my first app which is still on the emulator. 我制作了第一个仍在模拟器上的应用程序。 So while testing out the second, I run it.
因此,在测试第二个时,我运行它。 The splash screen does it's job and then instead of going to the main activity of the app I'm testing, the app exits and a message comes up saying, complete the action by choosing either the first app or the second app I'm testing.
启动画面完成它的工作,然后不是去我正在测试的应用程序的主要活动,应用程序退出并显示一条消息,通过选择第一个应用程序或我正在测试的第二个应用程序来完成操作。 So how do I avoid this or make the app not give the user that option?
那么如何避免这种情况或让应用程序不向用户提供该选项呢?
EDIT: 编辑:
APP 1: APP 1:
MANIFEST: 表现:
<?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>
SPLASHSCREEN CODE: SPLASHSCREEN代码:
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 : MANIFEST: 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>
SPLASHSCREEN: 闪屏:
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();
}
}
The reason for this is both your app are different(means with different package names), While in your Androidmanifest file of both applications you have specified same intent-filter for your MainActivity. 原因是您的应用程序不同(具有不同包名称的方式),而在两个应用程序的Androidmanifest文件中,您已为MainActivity指定了相同的intent-filter。 Please consider adding different intent-filters in both app.
请考虑在两个应用中添加不同的intent-filters。
<activity android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="com.example.yourcustom.intent"/>
</intent-filter>
</activity>
As in above example com.example.yourcustom.intent is intent filter registered for MainActivity Whenever you fires an intent, for handle that intent Android will do intent-resoltuion and give you option of all apps which can handle that intent, thats why you are getting application chooser dialog. 如上例所示, com.example.yourcustom.intent是为MainActivity注册的intent过滤器每当你触发一个intent时,对于那个意图Android会执行intent-resoltuion的句柄,并为你提供所有可以处理这个意图的应用程序的选项,这就是为什么你是获取应用程序选择器对话框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.