Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass Cursor Object to next Activity using Intents

I'm familiar with how to pass Raw Data(String, int, boolean etc) from one Activity to another Activity. But in my application, I want to pass a Cursor object to next Activity. I'm extending my class from the Activity Class.

Though I have looked at this post. but it provides cotradictory solutions. However, as described by one of the users, one should extend Application class to pass cursor data. But I want to extend Activity class. So is there any way to pass Cursor data from an Activity to another Activity.

Note- If it helps, the fact why I want to use the cursor is, I'm querying data for a particular contact clicked from the list and saving it in the cursor and I want to pass the same cursor data to the next Actvity.

like image 748
Sahil Mahajan Mj Avatar asked Dec 26 '12 07:12

Sahil Mahajan Mj


2 Answers

  • Re-query your cursor on the destination side.
  • Store the cursor data in a class which implements Parcelable.(when your cursor data is in small size).

Above both method will work perfectly, concern really coming when you dealing with Static ones.

Remember: To open/close cursor and database when required.

like image 198
Mohammed Azharuddin Shaikh Avatar answered Oct 11 '22 21:10

Mohammed Azharuddin Shaikh


your Cursor is just a reference of your requites query you executed to SQLite and passing Cursor it not good idea . Although if your data is not much sized then you can get data from Cursor and save it in any collection and pass it as serialized form to another activity via intent .

like image 43
Vipin Sahu Avatar answered Oct 11 '22 20:10

Vipin Sahu