如何避免启动Android应用程序两次,从Eclipse运行到实际设备



我正在从eclipse中运行应用程序,它被启动了两次:第一次启动应用程序,然后在几秒钟后再次重新启动

我的应用程序启动画面->>主活动(同时打开两次)。

我已经尝试在我的manifest文件中添加android:launchMode="singleInstance",但不成功。

我已经尝试了3个不同的应用程序,从我的eclipse仍然打开两次在我的Kitkat,棒棒糖真实设备(创建了一个也打开两次的新项目)

EDIT:

尝试在manifest文件中添加这行但不成功-android:launchMode="singleTop"

请告诉我如何解决这个问题。

清单文件:

<application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:launchMode="singleInstance"
        android:theme="@style/AppTheme2" >

        <activity
            android:name=".Start"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
</application>

My start Activity.java

public class Start extends Activity
{

        SessionManagerFor_Signin session;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Session class instance
        session = new SessionManagerFor_Signin(getApplicationContext());
         // Remove the Title Bar
       requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.start);

        ImageView Image1=(ImageView)findViewById(R.id.imageView1);
        //Animation Bottom to Top        
        TranslateAnimation animation2 = new TranslateAnimation(0.0f, 0.0f,400.0f, 0.0f); 
            animation2.setDuration(1000);  
            animation2.setFillAfter(false); 
            Image1.startAnimation(animation2);

        Thread timer = new Thread()
        {
        @Override
        public void run()
        {
            try {
                sleep(3000);

            } 
            catch (InterruptedException e) 
            {
            e.printStackTrace();    
            }
            finally
            {
                session.checkLogin();
                finish();
            }
        }
    };
    timer.start();

    //For Full Action bar Color Starts
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                setTranslucentStatus(true);
            }
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(R.color.FUllStartColor);
    //For Full Action bar Color Ends here           
}
    @TargetApi(19) 
    private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }

尝试在你的Manifest中添加launchMode "singleTop"到你的activity

<activity
  android:name="MyActivity"
  android:launchMode="singleTop"
  ... >

只在一个activity中应用intent filter。从MainActivity中移除…

<application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:launchMode="singleInstance"
        android:theme="@style/AppTheme2" >

        <activity
            android:name=".Start"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait" >
        </activity>
</application>

将此从两个活动之一中删除:

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

这个intent-filter指示Android哪个是Main Activity,你应该只有一个。

try this:

android:launchMode="singleTask"

这可能会起作用。

将下面的应用到您的闪屏活动中,然后清理项目并再次运行。

尝试用完整的包名在manifest文件中注册活动。

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

最新更新