1

I have two activites set up, an Inbox and Detail activity. The Inbox activity is just a ListView of messages, and the Detail view is the message itself once clicked on a cell.

Now I am initially passing in the objectID from parse and obtaining the intent data on the second activity just fine. I even constructed the method to delete the message and return to the initial inbox activity:

deleteButton.setOnClickListener(new View.OnClickListener() {

   @Override
   public void onClick(View v) {
      ParseObject.createWithoutData("User_Messages",
         messageObjectId).deleteInBackground(new DeleteCallback() {
            @Override
            public void done(ParseException e) {
               if (e == null) {
                  finish();
                  Toast.makeText(getApplicationContext(), 
                     "You have deleted your message", Toast.LENGTH_SHORT).show()
               }
            }
         });
      }
 });

Now the problem is that sometimes when returned back to the Inbox activity, the message still appears in the ListView even though in the onCreate/onResume of Inbox activity I have the Async task to obtain and set the adapter for the data. Since I have it finish(); in the done portion of parse's block I figure that the Inbox activity will call the async task to obtain / set adapter again, so why would it not be refreshing properly occasionally once users returned back?

2 Answers 2

2

Are you using YourAdapter.notifyDataSetChanged() ? or just notifyDataSetChanged() in your Adapter where you set the list ?

Sign up to request clarification or add additional context in comments.

4 Comments

Not using any of those actually, which may be my problem. Would the proper place to add this, instead of the async task, maybe be the method in the Inbox Activity that's called when finish() is called from the Detail activity? So that way notifyDataSetChanged is called when someone actually deletes an item, rather then everytime the Inbox Activity is loaded?
Sorry I forget which method to use or the name of it, for when finish() is called from the Detail activity. I believe there is a method that can be executed from the parent activity once finish() is called from child activity?
As I understand Detail Activity contains the Delete Button and Inbox the List ? So I can assume you click on one item in Inbox and it goes to the Detail Activity ? if its something like this then use an interface for delete thats notifys that there was a delete and the interface is implemented in InboxActivity where its method its like this onDelete(){adapter.notifyDataSetChanged}
Ah Interfaces! That's what I was looking for. I was initially I think overthinking it and was thinking of somehow using startActivityForResult, and then returning data back somehow. Thanks for the tip I forgot all about interfaces, I'm such a n00b.
1

i guess your adapter is caching your Data. You have to tell the adapter to update/reload it's Data. Try this, hope it works

adapter.notifyDataSetChanged();

2 Comments

Just unsure of where that would go, wouldn't I only want that to happen once the data is deleted? So I would maybe have to put it in the method thats called from Inbox Activity once finish() is called from Detail activity? Since the adapter ultimately resides in my Parent Activity (Inbox), and the delete buttons in my Detail activity
And by the method thats called, I thought there is a method that can be used in the MainActivity to check when finish() was called from a child activity

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.