If I have a reference to Context
, is it possible to finish the current activity?
I don't have the reference to current activity.
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
The Best Answer is getApplicationContext(); Wherever you are passing it pass this or ActivityName. this instead. you get this exception because you can't cast the Application to Activity since Application is not a sub-class of Activity .
yes, with a cast:
((Activity) ctx).finish();
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