Android how to call startActivityForResult inside adapter

I have an adapter class:

public class AdapterAllAddress extends BaseExpandableListAdapter { private Context context; public AdapterAllAddress(Context context, ArrayList<AllAddressesGroup> groups) { // TODO Auto-generated constructor stub this.context = context; } } 

I want to call startActivityForResult when a button is clicked, I know that I can call startActivity as follows:

 context.startActivity() 

but I am looking for work with results, how do you like?

+7
source share
2 answers
 yourButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(context, YourNewActivity.class); ((Activity) context).startActivityForResult(intent, resultCode); } }); 
+20
source

I just wanted to point out the detail that I encountered in my case E / ActivityThread (31584): Performing an activity stop that does not resume: {com.example.test / activities.MainActivity} most likely you pass getApplicationContext () to the adapter constructor. To avoid this, you must provide “ CallingActivity.this ” to the adapter constructor as an object of context , remember this.

+2
source

All Articles