App completely restarting when launched by icon press in launcher

前端 未结 14 2083
灰色年华
灰色年华 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: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

提交回复
热议问题