I'd like to know if it's a good idea to implement in all activities onBackPressed()
the finish()
function? Or it's not practical and not even good to do it?
If not, what other options besides going to manifest and input the SingleInstance
(which I think it makes the application more slow) in every activity, do I have?
Thanks.
First of all Hardware back button itself calls finish()
method. If you are defining onBackPressed()
Method in your activity it means you are overriding the default behavior of backButton as onBackPressed()
method gets called when you press back button.
Now whether to create a single instance of activity or not depends on your requirement, for e.g. splash screen can be made of a single Instance as it will be visible only once during start of app and there is no need to keep this activity in back stack. The activity you are going to use very often should not be single Instanced otherwise a rare activity can be made a single Instance.
Go through the Back Stack Documentation for complete information.
standard and 'singleTop' can instantiate multiple activity instances and the instance will stay in the same task. For 'singleTask' or 'singleInstance', the activity class uses the singleton pattern, and that instance will be the root activity of a new task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With