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 Sending Messages Sending the Message

6,862 Points

App doesn't go back to Inbox view automatically after Sending any "Picture/Video"

My app successfully sends a picture/video and outputs the "Success" message but still stays in the friend selection screen.

Here is my code.

How do I move it to Inbox immediately after pressing SEND just like Ben?

package com.dipnsa.dipdip;

import java.util.ArrayList;
import java.util.List;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseRelation;
import com.parse.ParseUser;
import com.parse.SaveCallback;

public class RecipentsActivity extends ListActivity {

    public static final String TAG = RecipentsActivity.class.getSimpleName();

    protected List<ParseUser> mFriends;
    protected ParseRelation<ParseUser> mFriendsRelation;
    protected ParseUser mCurrentUser;

    protected MenuItem mSendMenuItem;
    protected Uri mMediaUri;
    protected String mFileType;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_recipents, container,

        return rootView;


    public void onResume() {


        mCurrentUser = ParseUser.getCurrentUser();
        mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);


        ParseQuery<ParseUser> query = mFriendsRelation.getQuery();
        mFriendsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() {

            public void done(List<ParseUser> friends, ParseException e) {
                mMediaUri = getIntent().getData();
                mFileType = getIntent().getExtras().getString(ParseConstants.KEY_FILE_TYPE);
                    if (e == null)  {
                    mFriends = friends;                 
                    String[] usernames = new String[mFriends.size()];
                    int i = 0;
                    for(ParseUser user : mFriends) {
                        usernames[i] = user.getUsername();
                    ArrayAdapter<String> adapter = new ArrayAdapter<String>(


                else {
                    Log.e(TAG, e.getMessage());
                    AlertDialog.Builder builder = new AlertDialog.Builder(RecipentsActivity.this);
                        .setPositiveButton(android.R.string.ok, null);
                    AlertDialog dialog = builder.create();



    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.recipents, menu);
        mSendMenuItem = menu.getItem(0);
        return true;


    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()) {
        case android.R.id.home:
            return true;
            case R.id.action_send:
                ParseObject message = createMessage();
                if (message == null) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    .setTitle("Test Title")
                    .setPositiveButton(android.R.string.ok, null);
                    AlertDialog dialog = builder.create();
                } else {

                return true;
        return super.onOptionsItemSelected(item);

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

        if (l.getCheckedItemCount() >0 ) {
        else {

    protected ParseObject createMessage() {
        ParseObject message = new ParseObject(ParseConstants.CLASS_MESSAGES);
        message.put(ParseConstants.KEY_SENDER_ID, ParseUser.getCurrentUser().getObjectId());
        message.put(ParseConstants.KEY_SENDER_NAME, ParseUser.getCurrentUser().getUsername());
        message.put(ParseConstants.KEY_RECIPENT_IDS, getRecipentIds());
        message.put(ParseConstants.KEY_FILE_TYPE, mFileType);

        byte[] fileBytes  = FileHelper.getByteArrayFromFile(this, mMediaUri);

        if (fileBytes == null) {
            return null;
        else {
            if (mFileType.equals(ParseConstants.TYPE_IMAGE)) {
                fileBytes = FileHelper.reduceImageForUpload(fileBytes);

            String fileName = FileHelper.getFileName(this, mMediaUri, mFileType);
            ParseFile file = new ParseFile (fileName, fileBytes);
            message.put(ParseConstants.KEY_FILE, file);

            return message;

    protected ArrayList<String> getRecipentIds() {
        ArrayList<String>   recipentIds = new ArrayList<String>();
        for (int i = 0; i<getListView().getCount(); i++) {
            if (getListView().isItemChecked(i)) {
        return recipentIds;

    protected void send(ParseObject message) {
        message.saveInBackground(new SaveCallback() {

            public void done(ParseException e) {
                if (e == null) {

                    Toast.makeText(RecipentsActivity.this, R.string.message_sent, Toast.LENGTH_LONG).show();
                else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(RecipentsActivity.this);
                    .setPositiveButton(android.R.string.ok, null);
                    AlertDialog dialog = builder.create();


1 Answer