App completely restarting when launched by icon press in launcher

前端 未结 14 1937
灰色年华
灰色年华 2020-11-29 03:02

I\'m in the process of trying to make a release build of my first android app to send to a few testers. However, I ran into a problem with it. When you exit the app and then

相关标签:
14条回答
  • 2020-11-29 03:41

    For me, I found that I had erroneously posted NoHistory = true in my activity attribute

    [Activity(NoHistory = true, ScreenOrientation = ScreenOrientation.Landscape)]
    

    This prevented the app resuming into this activity and restarted

    0 讨论(0)
  • 2020-11-29 03:42

    All of the solutions above didn't work consistently on all of my devices. It worked on some Samsung but not all.

    The cause of the problem for me was installing the APK manually.

    0 讨论(0)
  • 2020-11-29 03:44

    Add this to your first activity:

    if (!isTaskRoot()) {
            finish();
            return;
    }     
    super.onCreate(savedInstanceState);
    
    0 讨论(0)
  • 2020-11-29 03:48

    You could use launchMode as singleTop to the Launcher Activity in AndroidManifest.xml

           <activity
            android:name="<YOUR_ACTIVITY>"
            android:label="@string/app_name"
            android:launchMode="singleTop">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
    0 讨论(0)
  • 2020-11-29 03:51

    For me the fix was adding LaunchMode = LaunchMode.SingleTop to my Activity attribute over the Main Activity:

    /// <summary>
        /// The main activity of the application.
        /// </summary>
        [Activity(Label = "SilhuettePhone",
            Icon = "@drawable/icon",
            Theme = "@style/MainTheme",
            MainLauncher = true,
            ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
            ScreenOrientation = ScreenOrientation.Portrait,
            LaunchMode = LaunchMode.SingleTop,
            WindowSoftInputMode = SoftInput.AdjustResize)]
    
    0 讨论(0)
  • 2020-11-29 03:52
     // To prevent launching another instance of app on clicking app icon 
            if (!isTaskRoot()
                    && getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
                    && getIntent().getAction() != null
                    && getIntent().getAction().equals(Intent.ACTION_MAIN)) {
    
                finish();
                return;
            }
    

    write the above code in your launcher activity before calling setContentView. This will solve the problem

    0 讨论(0)
提交回复
热议问题