简体   繁体   中英

Passing parse data from fragment list item click to new activity

This code runs when you click on someone in the friends list.

ProfileActivity.class is essentialy just a blank list right now. I need to know how to get the new ProfileActivity to save the list item that was clicked and then pull all the info on that user from parse and display in new ProfileActivity. Thanks!

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Intent intent = new Intent(getActivity(), ProfileActivity.class);

    startActivity(intent);
    };

Why don't use bundles ? You can attach Bundle object to your intent, which then can be retrieve into the ProfileActivity by doing getIntent().getExtras().

Look at the bundle here : Bundle

And how to attach it to the intent here : Intent

Assuming you are reffering to parse.ocm

Wheter using the subclassing feature or not, ParseObjects are unfortunately not serializable nor parcable.

My current solution is to keep a reference to the 'detail' object in a Singleton object held by Dagger: http://square.github.io/dagger/

Thought it is working, I am not happy with this solution.

My suggestion is to look into EventBus https://github.com/greenrobot/EventBus . I found this great article about it here: http://www.stevenmarkford.com/passing-objects-between-android-activities/ and it looks like it is beautifully easy to implement, performs well too!

Unfortunately I have not yet tried using EventBus, but seems like the way to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM