Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes the callback from the handler when the activity is destroyed #361

Open
wants to merge 3 commits into
base: bug-fixes
Choose a base branch
from
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