-1

I am having an activity, which has a view and when we click on this view another activity gets started.

In the second activity I am having a List View and adding data to it using an adapter. Now in the adapter I am having some options when I click on these options the current activity will be stopped and the parent activity from which this activity was started, needs to be restarted.

How can I achieve this from that adapter class, so that the current activity gets finished and the parent activity gets refreshed.

Thanks in advance !!!

Hans1984
  • 796
  • 11
  • 24
Prithniraj Nicyone
  • 5,021
  • 13
  • 52
  • 78
  • 1
    possible duplicate of [How to finish an activity from an Adapter..?](http://stackoverflow.com/questions/7951936/how-to-finish-an-activity-from-an-adapter) – 2Dee Jul 31 '15 at 08:05
  • Google search time : 4 seconds... Definitely less time than writing this question. – 2Dee Jul 31 '15 at 08:06
  • Yes, I am able to manage the finish of the current activity, but I need to restart the parent activity also, how can I do that, please help me if you have any idea to do this. Thanks.. – Prithniraj Nicyone Jul 31 '15 at 08:06
  • I need to refresh the parent activity from the adapter class. – Prithniraj Nicyone Jul 31 '15 at 08:08

1 Answers1

1

use setOnItemClickListener of your listview and call the parent activity where it calls onResume() of your parent activity.

  • so you would have him keep a hard reference to the parent activity in the adapter ? – 2Dee Jul 31 '15 at 08:08
  • You can create interface and pass the parent context to the adapter constructor then you can set the required data to the interface from your adapter class then can use it as a response listener from your parent activity to process further. – Prithviraj Shiroor Jul 31 '15 at 08:11
  • Have you tried this ? I would expect the parent Activity to be null, since the user already moved on to another Activity... – 2Dee Jul 31 '15 at 08:15
  • yes i have tried, if you want to send back some data to parent activity you can do so by using interface. – Prithviraj Shiroor Jul 31 '15 at 08:17
  • I'll give it a try when I get home, I'm really interested to know what happens behind the scene. Just to be clear, what you're saying is Activity A -> Activity B -> adapter created from Activity B -> call to Activity A's lifecycle methods ? I don't understand how that's possible. Do you know if Activity A is retained in the heap ? so I can avoid testing this myself altogether :) – 2Dee Jul 31 '15 at 08:31
  • lifecycle methods is other way, what i said is to just trigger the interface with required data so that u can call any activity from another activity, comment here what u get once you try, I will help you further to get clear idea on this. – Prithviraj Shiroor Jul 31 '15 at 09:14