0
votes

I have a standard master-detail scenario. But, I need to perform updates/deletes to a detail item (which is easy), and then return to the list item view from which I selected the item to update with the row updated. All the data is handled by contentprovider and I am aware of updating my adapter. I cannot figure out how to do get back to the listview. Any ideas are appreciated.

1

1 Answers

0
votes

You can use startActivityForResult() method to get result from another activity.

First, you have to use startActivityForResult in master Activity.

     Intent intent=new Intent(MainActivity.this,SecondActivity.class);  
     startActivityForResult(intent, 2);// Activity is started with requestCode 2  

You can set data in detail Activity and get it back in caller Activity. Just put data in detail Activity like this:

Intent result=new Intent();  
result.putExtra("MESSAGE",message);  
setResult(10, result);  
finish();//finishing activity

Here 10 is result code of the detail Activity, you can provide different result code for different type of result.

Here's how you will get result back in caller Acitvity, just override onActivityResult() method.

 @Override  
 protected void onActivityResult(int requestCode, int resultCode, Intent data)  {  
             super.onActivityResult(requestCode, resultCode, data);  
             // check for the request code and result code                   
             if(requestCode==2 && resultCode == 10)  {  
                        String message=data.getStringExtra("MESSAGE");   
                        textView1.setText(message);  
             }  
 }