Open akshaydmc opened 4 years ago
@AkkiBond I think this can be fixed by raising the alert dialog before closing the app or showing a toast notification if the user presses back button first time like "Press again for closing the app"
Yes But it should only be when user presses back button two times. Otherwise what is the use of back button if we can't go back to our last activity.
@AkkiBond yes on first press it will show the toast and then it will ask for pressing it again.
@robustTechie I'm trying to trace that problem and fix it with a PR.
Open Discussions in #7 , #29, #42 , #64, #110
duplicate of #143
Developer should not display URL's on network failure. You can hide such webview based errors by display static web page on getting any webpage access error:
webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { webView.loadData("
", "text/html", null);}
}
Also you can minimize the app on pressing back button..
@Override public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (webView.canGoBack()) { webView.goBack(); } else { moveTaskToBack(true); } return true; } } return super.onKeyDown(keyCode, event); }
Same replied on #143
Or we can just use the addToBackStack() and that would make sure we go back to the previous activity and if there is none the app exits.
@AkkiBond Please check for existing issues before opening a new one. You can close this and proceed there. Duplicate of #7
There is problem with Intent that doesn't save the last activity because of that the app directly closes rather than going back to last running activity. like in FAQ section when we try to get back to last activity it closes the whole application.
We need to use Intents to "switch windows". To launch another Activity from our current Activity, simply create an Intent with a few parameters and call startActivity() with that Intent. Here's an example:
Intent i = new Intent(this, TheNextActivity.class); startActivity(i)
Don't forget to include your second Activity in the Android manifest file. All Activities in your application must be included in that file.
Other things to note is that we don't really use System.exit() in Android. Just call finish(). It's advised to let Android manage applications and its resources rather than doing it yourself, but if we want to make sure that your application really is shut down, feel free to use System.exit() anyway. There's also no need for overriding onBackPressed() if you're only calling finish(). That's standard behaviour in Android when we hit the back button.
Also, you don't call setContentView() more than once per Activity. You start a new Activity when you need to change the visuals (or use one of the specialized Widgets to switch between layouts.
This also explains why we're experiencing your "problem". You may have changed the layout of the Activity using setContentView(), but there's still only one Activity running - when you call finish(), that Activity gets closed. If you had started a second Activity with a different layout, like you're supposed to do, Android would have closed that second Activity and would have returned you to the first.