Android App closes properly but won't open again -
i working on app require closes when user press close button, managed make work using finish() function when starter activity called 1 instead of starting. when try open app again it's closes automatically.
loginactivity (app close button located):
public static final string closekey = "closekey"; //i cut off entire oncreate function show close app code cancel.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent = getbasecontext().getpackagemanager() .getlaunchintentforpackage( getbasecontext().getpackagename() ); i.addflags(intent.flag_activity_clear_top); i.putextra(closekey,"closeapp"); startactivity(i); finish(); } });
as can see send elemente on intent, indicate starter activity want app close.
loadingactivity (starter app):
bundle extras = getintent().getextras(); if(extras == null){ executeanim(); }else{ android.os.process.killprocess(android.os.process.mypid()); system.exit(0); finish(); }
the loadingactivity checks if there extras on intent, if there not trigger loading animation , go loadingactivity, , if there element close activity because it's indicating want close it.
i found way make work, had add few validations if/else in loadingactivity:
bundle extras = getintent().getextras(); if(extras == null){ executeanim(); }else if (extras.getstring(loginactivity.closekey) == null){ executeanim(); }else if (extras.getstring(loginactivity.closekey) == ""){ executeanim(); }else { try{ android.os.process.killprocess(android.os.process.mypid()); system.exit(0); finish(); }catch (exception ex){ ex.printstacktrace(); } }
Comments
Post a Comment