My app contains an initial splash screen, followed by a listview
(main activity). Clicking on each row of listview
opens each activity.
My requirement is that if we single press the back button from any of my inner activities (activities that are opened when we click the listview
rows), it must navigate to my main listview
, and then if we press once more from the listview
the app must gets closed.
So, if I press the back button from my listview
twice it will exit the app correctly. My main problem is that if I press the back button twice from any of my inner activities, my app is not getting closed. I need to press three times, instead of closing the app from any of my inner activities. Can anyone please help me ?
This is my code for exiting the app. I added this code in my main listview
class..
private static final int TIME_INTERVAL = 3000; // # milliseconds, desired time passed between two back presses.
private long mBackPressed;
@Override
public void onBackPressed()
{
if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis())
{
super.onBackPressed();
return;
}
else { Toast.makeText(getBaseContext(), "Tap back button in order to 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" >