Reputation: 251
I am new at developing Android App.I am try to use a dynamic fragment which is used 2 activity like (show detail activity and edit details activity).How can I understand the fragment is used by which activity in onActivityCreated()
method on MyFragment
class. How can I handle this issue please help me thanks in advance
Upvotes: 0
Views: 33
Reputation: 1709
Jagadesh's solution will work, but fragments should operate independent of the activity.
You might want to consider adding a static method like "getInstance" that will accept parameters and return an appropriate instance of the fragment if some functionality shoudl be custom for the calling activity.
If you want to call the activity back, then you might think about having the activities register a callback or listener that the fragment can invoke.
Upvotes: 0
Reputation: 2664
Try this in your Fragment onActivityCreated()
method
FragmentActivity activity = getActivity();
if(activity instanceof show detail activity){
// Your ShowDetailsActivity
}else if(activity instanceof edit details activity){
// Your EditDetailsActivity
}
Upvotes: 1