Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Self-Destructing Message Android App Self-Destruction Deleting Partial Data for One Recipient

john appleby
john appleby
2,773 Points

Inbox fragment doesn't refresh after delete or message received ?

hi Ben, My Inbox fragment doesn't refresh after delete or message received ? Ive checked my code against yours and I can't seem to find any errors..... I thought the onResume method would call for the list to be refreshed when the fragment came back into focus... is there a refresh method I could call after the data has changed on the Parse backend ?

my FragmentActivity:

package jma.lazylearn.rabbit;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;

import java.util.ArrayList;
import java.util.List;

public class InboxFragment extends ListFragment {

    protected List<ParseObject>  mMessages;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView;
        rootView = inflater.inflate(R.layout.fragment_inbox, container, false);

        return rootView;

    public void onResume() {


        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_MESSAGE);
        query.whereEqualTo(ParseConstants.KEY_RECIPIENT_IDS, ParseUser.getCurrentUser().getObjectId());
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> messages, ParseException e) {
                if (e == null){
                    mMessages = messages;
                    String[] usernames = new String[mMessages.size()];
                    int i = 0;
                    for (ParseObject message : mMessages){

                        usernames [i] = message.getString(ParseConstants.KEY_SENDER_NAME);

                    if (getListView().getAdapter() == null){
                    MessageAdapter adapter = new MessageAdapter(getListView().getContext(), mMessages);
                    else {




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

        ParseObject message = mMessages.get(position);
        String messageType = message.getString(ParseConstants.KEY_FILE_TYPE);
        ParseFile file = message.getParseFile(ParseConstants.KEY_FILE);
        Uri fileUri = Uri.parse(file.getUrl());

        if (messageType.equals(ParseConstants.TYPE_IMAGE)){
            Intent intent = new Intent(getActivity(), ViewImageActivity.class);
        else {
            Intent intent = new Intent(Intent.ACTION_VIEW, fileUri);
            intent.setDataAndType(fileUri, "video/*");


        List<String> ids = message.getList(ParseConstants.KEY_RECIPIENT_IDS);

        if (ids.size() == 1) {

        else  {
            ArrayList<String> idsToRemove = new ArrayList<String>();

            message.removeAll(ParseConstants.KEY_RECIPIENT_IDS, idsToRemove);



I m a it stuck and want to jazz my UI up a bit.

thanks for any help John

1 Answer

Ben Jakuben
Ben Jakuben
Treehouse Teacher

It looks good and you're right; it should refresh when it comes back into view. Hmmm. Can you try inserting some log statements in your onResume() and done() methods to see if anything gets logged?