• Latest Code...

    Refresh activity on back button in android

    Normally, when user click the back button in android, the next view is not refreshed. I had this problem when I was doing the settings. if user changed the some settings and hit back button, the new settings won’t be applied to the “back” list view since all the cells are reused.
    you can do some scroll to refresh the list view but that is definitely not something we wanna user to do.
    first solution is to override the onResume method in the back view, but it is not guaranteed to work in listView.
    However the following code should do the work:

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && isNightModeToggled) {
            Intent a = new Intent(this,MainActivity.class);
            return true;
        return super.onKeyDown(keyCode, event);

    Happy Coding!!!!

    No comments:

    Post a Comment


    Most recent Elastic Search tutorials for beginner, intermediate and advance level developer, Yubraj Pokharel, in CodingWorkspace