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

标签 android eclipse android-manifest main-activity

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

我的应用启动画面--->>主要 Activity (都打开两次)。

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

我已经尝试了 3 种不同的应用程序,我的 eclipse 仍然在我的 Kitkat , lollipop real device 中打开了两次(创建了一个也打开了两次的新项目)

编辑 1:

尝试在 list 文件中添加这一行但没有成功-android:launchMode="singleTop"

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

list 文件:

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

我的启动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);
    }

最佳答案

尝试在您的 Activity list 中添加 launchMode“singleTop”。

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

关于android - 如何避免两次启动 Android 应用程序,从 Eclipse 运行到真实设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32758700/

相关文章:

android - 如何检索设备上可用的最大堆?

Android Multi-tracker 示例项目运行但未显示任何形式的检测

android - 为什么我的可组合不会在更改 HashMap 的 MutableState 值时重新组合?

java - 软件开发人员!不适用于 Eclipse.app 或 SpringToolSuite4.app(在 Mac 上)

java - 在项目的构建路径中检测到一个循环...eclipse

具有多个 Activity 的 Android 应用

android - 设置安卓 :hardwareAccelerated ="true" in <activity> or in <application>

php - Android:使用 volley 将数据发布到 laravel 服务器时出现意外响应代码 500

android - 如果在股票浏览器上受密码保护的站点后面,则 APK 下载失败

java - 在 WindowBuilder Eclipse 中更改 JFrame