Question

I'm using 'twitter4j' to make a twitter client app. and I want to bypass the Twitter object from the MainActivity.java to different fragments in my app to be used by them. what is the best way to do that?

I don't know if i can do it with 'Bundle' ?!

and when I tried to make a constructor for my fragment for example: public Fragment_a(Twitter twitter) { // } i got a warning from eclipse saying that: "Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle)"

thanks

Was it helpful?

Solution

You could implement the twitter object in your activity, and then just let your fragments grab it

twitterObject = ((MyActivity)getActivity()).getTwitterObject();
if (twitterObject != null)
{
    // do something
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top