1

I have uploaded data onto parse.com and i am trying to retrieve the data from parse.com and display it in a textview.

i have a parseconstants class:

public static final String TYPE_STRING = "string"; 
public static final String KEY_FILE_TYPE = "fileType";

i send the message and it uploads to parse fine

String fileName = "text.txt";
        String fileType = "text";

these 2 values are sent to parse.com as filename and filetype.

but when i get it back in inboxActivity here:

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

        ParseObject message = mUserBio.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_STRING)){
            Intent intent = new Intent(getActivity(), ViewTextActivity.class);
            intent.setData(fileUri);
            startActivity(intent);
        }

it does not call on the text activity class and does not show the class.

in the TextViewController i try to display the text into the TextView like below:

mDisplay = (TextView)findViewById(R.id.bioDisplay);

    Uri textUri = getIntent().getData();
    File string = new File(textUri.toString());
    mDisplay.setText((CharSequence) string);

1) Why does the ViewtextActivity not show?

2) will the textview display the retrieved user bio?

1 Answer 1

3

Firstly, try to avoid calling constants like this:

ParseConstants.KEY_FILE_TYPE

Completely!

Rather import your class statically:

import static <your_package_name>.ParseConstants.*;
//now you can access your constants by calling it on its own:
String messageType = message.getString(KEY_FILE_TYPE);

EDIT

Your naming standards are not up to standard (An instance of File, should be called something to do with a File, and not "string")!! You are trying to display an object of type File within a TextView which won't work. Rather try this, instead of letting Android Studio cast it to a CharSequence:

mDisplay.setText(string.toString());

Thirdly, when calling ViewTextActivity, there are 3 ways to do this (as I am not sure if you are using a Fragment or not):

//if you are using a Fragment:
Intent intent = new Intent(getActivity(), ViewTextActivity.class);

//if you are using a FragmentActivity, you need to cast it:
Intent intent = new Intent((Your_Base_Activity) getActivity(), ViewTextActivity.class);

//if you are using a normal activity:
Intent intent = new Intent(Your_Activity_Name.this, ViewTextActivity.class);

As far as your TextView displaying data is concerned, your code does seem logically correct.

EDIT 2

From the ParseObject API, we see that getString will return the String value from that Key that is put in as the parameter (See Here).

According to you, you are checking if the return value is equal to the word "string". This doesn't make sense, as you are putting in the key value of "fileType".

My suggestion is check if the return is not null by using a log:

String messageType = message.getString(KEY_FILE_TYPE);
Log.e("MessageReturned: ", "Returned-" + messageType);

Or you can rethink, what the value that is supposed to equate to is supposed to be, as "string" doesn't make sense as far as I can see.

EDIT 3

Since you are saying that the value uploaded for the variable fileType is "text" should you not rather be doing this:

if (messageType.equals("text")){

EDIT 4

Your method of parsing information between the intents is obsolete. You need to try this:

if (messageType.equals(ParseConstants.TYPE_STRING)){
        Intent intent = new Intent(getActivity(), ViewTextActivity.class);
        intent.putExtra("fileUri", fileUri.toString());
        startActivity(intent);
}

Then in your other class, you access it like so:

Bundle extras = getIntent().getExtras(); 
Uri receivedFileUri = Uri.parse(extras.getString("fileUri"));
Sign up to request clarification or add additional context in comments.

14 Comments

i am using fragments and when i type mDisplay.setText(String) it does not let me and adds (CharSequence)
thanks, the mDisplay.setText(string.toString()); works with no errors. i think why the viewTextActivity does not show is that i save my filetype as text (see question) and then i say (messageType.equals(ParseConstants.TYPE_STRING)) TYPE_STRING is set to string in ParseConstants is that why it wont show?
I'm uploading user inputted text and saving it as file type text and file name text.txt then I'm am getting it back and displaying in text view
Check my answer again. You are setting the key "fileType" to "text" when uploading. So why are you checking if the returned value is equal to "string" instead of "text"?
from the log message i got E/MessageReturned:﹕ Returned-text but the VeiwTextActivity did not show with the changes made
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.