I m getting NullPointerException whenever I try this-
getCallingActivity().getClassName()
I want to get the name of the caller/parent
acitivity from the called/child
activity.
I m getting NullPointerException whenever I try this-
getCallingActivity().getClassName()
I want to get the name of the caller/parent
acitivity from the called/child
activity.
If you check the doc getCallingActivity
returns the value only if the calling activity is expecting result i.e only if the activity is started with call to startActivityForResult
So for most cases this wont work. A better approach would be to pass the value through intent. Check this post
it's possible your calling activity is finishing sooner than you're expecting it to. this happened to me and resulted in a null return from getCallingActivity, even though the calling activity was using startActivityForResult
the caller and called Activities must be in one task. that is, you cannot start the called activity with any flag likes Intent.FLAG_ACTIVITY_NEW_TASK