clicking on the android back button twice to exit the app -
clicking on the android back button twice to exit the app -
i had asked question unfortunately cant find improve solution regarding issue.now app contains first screen splash screen next listview(main activity) clicking on each row of listview opens each activity , requirement if press 1 time button of inner activities(activities openend when click listview rows)it must navigate main listview , if press 1 time more listview app must gets closed.so if press button listview twice exit app correctly .but main problem if press button twice of inner activities app not getting closed need press thrice instead of closing app of inner activities.can please help me ?
my code exiting app added code in main listview class..
private static final int time_interval = 3000; // # milliseconds, desired time passed between 2 presses. private long mbackpressed; @override public void onbackpressed() { if (mbackpressed + time_interval > system.currenttimemillis()) { super.onbackpressed(); return; } else { toast.maketext(getbasecontext(), "tap button in order exit", toast.length_short).show(); } mbackpressed = system.currenttimemillis(); } }
my manifest.xml
<application android:allowbackup="true" android:label="@string/app_name" android:theme="@style/apptheme"> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> <activity android:name="learnersseries.mathematics.complexnumbers.firstintro" android:screenorientation="portrait" android:launchmode="singletop" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="myintegralpage" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="myimagine" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="myintroductionpage" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="mainactivity" android:nohistory="false" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="complexnumbers" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="equality" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="additionofcomplex" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="subtraction" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="multiplication" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="division" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="conjugate" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="modulus" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="reciprocal" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="square" android:screenorientation="portrait"> </activity> <activity android:name="representation" android:screenorientation="portrait" > <intent-filter></intent-filter> </activity> <activity android:name="argument" android:screenorientation="portrait" >
try way,hope help solve problem.
take 1 flag doublebacktoexitpressedonce default (false ) in activity , when button pressed first time flag value changed (ture) , 1 time again button pressed within 2 sec exit app if button 1 time again not pressed within 2 sec set flag value (false).
private boolean backpressedtoexitonce;
@override public void onbackpressed() { if (doublebacktoexitpressedonce) { super.onbackpressed(); return; } this.doublebacktoexitpressedonce = true; toast.maketext(this, "press 1 time again exit", toast.length_short).show(); new handler().postdelayed(new runnable() { @override public void run() { doublebacktoexitpressedonce=false; } }, 2000); }
android
Comments
Post a Comment