Mohammed Gadiwala Mohammed Gadiwala - 1 year ago 64
Android Question

How to get the name of the activity from the fragment?

So basically i am going to use one Fragment in two different activities.Except one method of fragment in which I want to change something.So how do i get the name of activity which is using the Fragment so that I can do things depending upon the name of which activity is current.

Answer Source



But be careful when you're using getActivity() method from fragment. If your fragment is not attached to activity getActivity() will return null.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download