Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class HomeActivity extends AppCompatActivity
private final String FRAGMENT_TAG_PROJECT = "Project";
private final String FRAGMENT_TAG_APK = "Apk";
private boolean backPressedOnce = false;
private Runnable runnable;
private Handler handler = new Handler();
private long timer = 2000;

private SmoothNavigationToggle smoothNavigationToggle;

Expand Down Expand Up @@ -211,16 +214,17 @@ public void onBackPressed() {
finish();
}
if(!backPressedOnce)
Toast.makeText(this, "Tap back once more to exit.", Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.tap_to_exit, Toast.LENGTH_SHORT).show();
backPressedOnce=true;
new Handler().postDelayed(new Runnable()
runnable = new Runnable()
{
@Override
public void run()
{
backPressedOnce= false;
backPressedOnce = false;
}
}, 2000);
};
handler.postDelayed(runnable , timer);
} else {
fragmentManager.beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.replace(R.id.container, new HomeFragment(), FRAGMENT_TAG_HOME).commit();
Expand All @@ -230,6 +234,16 @@ public void run()
navigationView.setCheckedItem(R.id.nav_home);
}
}

@Override
protected void onDestroy() {
super.onDestroy();
if (handler != null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also reformat your new changes.

{
handler.removeCallbacks(runnable);
}
}

}


Expand Down
1 change: 1 addition & 0 deletions source-code/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<string name="menu_home">Home</string>
<string name="buildmlearn_welcome_title">Welcome to BuildmLearn Toolkit</string>
<string name="welcome">Welcome</string>
<string name="tap_to_exit">Tap back once more to exit.</string>

<!--Snackbar-->
<string name="snackbar_deleted_message">Item deleted</string>
Expand Down