How to Avoid Launching the Android Application Twice ,Running from Eclipse to real device
Asked Answered
K

5

7

I am Running the application from eclipse and it's being launched twice: first time launching the app, then again relaunching after few seconds

My app Splash Screen--->> Main activity(Both Opening twice).

i already tried adding android:launchMode="singleInstance" in my manifest file, but not success.

i have tried 3 different applications from my eclipse still opening twice in my Kitkat ,lollipop real device (created new project that one also opening twice)

EDIT 1 :

Tried adding this line in manifest file but not Success-android:launchMode="singleTop"

please let me know How to solve this issue.

manifest file:

<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);
    }
Kenya answered 24/9, 2015 at 10:10 Comment(2)
i have tried 3 different applications from my eclipse still opening twice in my real device Kitkat ,lollipop(also created new project that one also opening twice)Kenya
Have you got any solution? I'm also facing same issue. Please help me to overcome this issue.Prager
N
3

Try adding launchMode "singleTop" in your Manifest to your activity.

<activity
  android:name="MyActivity"
  android:launchMode="singleTop"
  ... >
Nodose answered 24/9, 2015 at 12:59 Comment(0)
M
2

Remove this from one of the two activities:

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

This intent-filter indicates to Android which is the Main Activity, and you should have one only.

Mazzard answered 24/9, 2015 at 10:13 Comment(1)
i have tried 3 different applications from my eclipse still opening twice in my real device Kitkat ,lollipop(also created new project that one also opening twice) but working good in jellybean device.Kenya
P
2

Apply intent filter only in one of your activity. Remove from 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>
Pandiculation answered 24/9, 2015 at 10:14 Comment(4)
Can you please post your start activity code snippetPandiculation
i added my start activityKenya
this might be a eclipse issue?Kenya
ya i tried 3 applications opening 2 times why? running from eclipse to real deviceKenya
I
1

try this:

android:launchMode="singleTask"

May be this will work. If it does not work then reinstall eclipse.

Interloper answered 25/9, 2015 at 10:32 Comment(1)
i want to reinstall the eclipse or Sdk?Kenya
F
0

Apply the below to your splash screen activity,then clean the project and run again..

Try to register activity in manifest file with complete package name.

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Felon answered 24/9, 2015 at 10:39 Comment(3)
this might be a Eclipse issue?Kenya
Have u checked in in real device ??Felon
ya i have tested in real device, twice openingKenya

© 2022 - 2024 — McMap. All rights reserved.