Frage

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

War es hilfreich?

Lösung

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
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top