I am creating an application in android and I want to store data of places user selected on the google map. I am currently storing all the places by adding them all in an array and then serialize them by Gson library and it works fine and coding is very simple and easy but if i use data base instead of that that then the coding will be more complex and because implantation of data base is more complex then simply string the array of places to shared preferences. below is the class whose objects are i am storing and saving in the shared preferences but if want to store them on the data base then i have to go through more complex I have to create queries for insert, delete update etc. so suggest me that should i use db or shred preference is good for saving list of places.
package com.example.googlemapstext;
import java.util.ArrayList;
import android.location.Address;
public class MyPlace {
private int id;
private String placeName;
private Address placeAddress;
private int ringerState;
private int brightnessState;
private int wifiState;
private int gpsState;
private int bluetoothState;
private int radiusValueIndex;
private ArrayList<Contact> contactArrayList;
private String message;
private double radiusValue;
private boolean notificationCheck;
public MyPlace(int id,String placeName, Address placeAddress, String radiusValue,
int ringerState, int brightnessState, int wifiState, int gpsState,
int bluetoothState, int radiusValueIndex, ArrayList<Contact> contactArrayList,
String message, boolean notificationCheck) {
this.id=id;
this.placeName = placeName;
this.placeAddress = placeAddress;
this.radiusValue = getTrimedRadiusValue(radiusValue);
this.ringerState = ringerState;
this.brightnessState = brightnessState;
this.wifiState = wifiState;
this.gpsState = gpsState;
this.bluetoothState = bluetoothState;
this.contactArrayList = contactArrayList;
this.message = message;
this.radiusValueIndex = radiusValueIndex;
this.notificationCheck = notificationCheck;
}
private double getTrimedRadiusValue(String radiusValue)
{
radiusValue=radiusValue.replace("Radius ", "");
radiusValue=radiusValue.replace(" Meters", "");
return Double.parseDouble(radiusValue);
}
public boolean getNotificationCheck() {
return notificationCheck;
}
public void setNotificationCheck(boolean notificationCheck) {
this.notificationCheck = notificationCheck;
}
public int getRadiusValueIndex() {
return radiusValueIndex;
}
public void setRadiusValueIndex(int radiusValueIndex) {
this.radiusValueIndex = radiusValueIndex;
}
public int getRingerState() {
return ringerState;
}
public void setRingerState(int ringerState) {
this.ringerState = ringerState;
}
public int getBrightnessState() {
return brightnessState;
}
public void setBrightnessState(int brightnessState) {
this.brightnessState = brightnessState;
}
public int getWifiState() {
return wifiState;
}
public void setWifiState(int wifiState) {
this.wifiState = wifiState;
}
public int getGpsState() {
return gpsState;
}
public void setGpsState(int gpsState) {
this.gpsState = gpsState;
}
public int getBluetoothState() {
return bluetoothState;
}
public void setBluetoothState(int bluetoothState) {
this.bluetoothState = bluetoothState;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public double getRadiusValue() {
return radiusValue;
}
public void setRadiusValue(String radiusValue) {
this.radiusValue = getTrimedRadiusValue(radiusValue);
}
public String getPlaceName() {
return placeName;
}
public void setPlaceName(String placeName) {
this.placeName = placeName;
}
public Address getPlaceAddress() {
return placeAddress;
}
public void setPlaceAddress(Address placeAddress) {
this.placeAddress = placeAddress;
}
public ArrayList<Contact> getContactArrayList() {
return contactArrayList;
}
public void setContactArrayList(ArrayList<Contact> contactArrayList) {
this.contactArrayList = contactArrayList;
}
public int getId() {
return id`enter code here`;
}
public void setId(int id) {
this.id = id;
}
}
The main difference between SharedPreferences and DataBase is like you mentioned :
SharedPreferences works on an Key-Value pair basis. you simply provide the Key and get back the Value you stored. that's great.
DataBase creates an SQLite Tables and you need to use queries to pull them out.
I think that if you are good with the JSON mechanism that you built, then storing a string in SharedPreferences is all you need.
But when the Data get more and more complex, and you would like quick access to any part of it, I think DB would be easier than parsing and seaching a JSON string all the time.
Yes, it might make you write more code for handling the DB queries..
I think SQLite will be better for you. I only use SharePreferences for small, simple and "key - value" structured data. (and it should be like that)
You have a lot of data, so SQLite is the way to go.
Read this for more information : Pros and Cons of SQLite and Shared Preferences
I think answer depends on how many places you want to save and what do you plan to do with them but I consider DB as hte best way to go.
With a DB you will be able to create queries to get only places you want and not load all places in a list and search in it.
To simplify DB creation (and use) you can try orm for Android like OrmLite and GreenDao. I think OrmLite is easier to use than GreenDao (but second one seems to have better performance...) and you can find multiple examples there.
In my opinion, SharedPreferences should only be used for saving user preferences data.
Related
i am trying to get session stored variable in to a class. please see my actual code for class
public class GetDataAdapter {
public String ImageServerUrl;
public String ImageTitleName;
public String ImageUrlName;
public String getImageServerUrl() {
return ImageServerUrl;
}
public void setImageServerUrl(String imageServerUrl) {
this.ImageServerUrl = imageServerUrl;
}
public String getImageTitleName() {
return ImageTitleName;
}
public void setImageTitleNamee(String Imagetitlename) {
this.ImageTitleName = Imagetitlename;
}
public String getImageUrlName() {
return ImageUrlName;
}
public void setImageUrlNamee(String Imageurlname) {
this.ImageUrlName = Imageurlname;
}
}
now i stored a value in session and i want to use in above code. Imageurlname is a url fetching from database. i want to add extra to the url. for example
this is my URl Getting form database http://example.com?id=
i stored user id in session so combining both url should be http://example.com?id=5
please see my modified code
public class GetDataAdapter extends AppCompatActivity {
public String ImageServerUrl;
public String ImageTitleName;
public String ImageUrlName;
private Session session;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
session = new Session(GetDataAdapter.this);
HashMap<String, String> user = session.getUserDetails();
final String Uid = user.get(session.KEY_UID);
}
public String getImageServerUrl() {
return ImageServerUrl;
}
public void setImageServerUrl(String imageServerUrl) {
this.ImageServerUrl = imageServerUrl;
}
public String getImageTitleName() {
return ImageTitleName;
}
public void setImageTitleNamee(String Imagetitlename) {
this.ImageTitleName = Imagetitlename;
}
public String getImageUrlName() {
return ImageUrlName;
}
public void setImageUrlNamee(String Imageurlname) {
this.ImageUrlName = Imageurlname + Uid;
}
}
Uid is getting error. i hope you understand.
Looks like the problem is with persisting the userid in your case it is because of this.
Using instance variable to store user id which you can get only if you are getting the same object
Here are the solution(s):
Solution 1:
Using Static Variables
public class Example {
//this is the default value which will there stored before we are setting our actual userId
public static String USER_ID="DefaultId";
}
You can set and access the values this way.
Log.d("Default Value",Example.USER_ID);
//setting user id here
Example.USER_ID = "Manikanta Garikipati";
Log.d("Updated value",Example.USER_ID);
Solution 2: Using Shared preferences.
As you already know about this i would explain anyway.
Comment below if your problem is still not solved.
Here is the brief summary of the problem
The problem is not in shared preferences neither any storage.
Instead of creating a bean alone and setting the values to it , bean is extended with Activity etc.. which made things haywire..
Those who want the complete solution can go through the conversation in question.
Application class is there for you. use it and save your application level data, like this:
public class WhatEverApp extends Application
{
String mApplicationLevelVar = "Hello";
}
WhatEverApp will be the name of your app used in manifest.xml
Look here for detailed discussion on Application class.
I am the begginer android developer. I have a problem about saving shopping cart data temporary. It's a custom shirts app. Guest should select collar, cuffs, and so on.
I used listview to show these selected items and options which guest selected.
public class Cart_item_list {
private static int cart_itemimage;
private static String cart_itemname;
private static String cart_itemprice;
private static String cart_collar;
private static String cart_cuffs;
private static String cart_placket;
private static String cart_pocket;
private static String cart_fit;
private static String cart_initial;
public static int getCart_itemimage() {
return cart_itemimage;
}
public static void setCart_itemimage(int cart_itemimage) {
Cart_item_list.cart_itemimage = cart_itemimage;
}
public static String getCart_itemname() {
return cart_itemname;
}
public static void setCart_itemname(String cart_itemname) {
Cart_item_list.cart_itemname = cart_itemname;
}
public static String getCart_itemprice() {
return cart_itemprice;
}
public static void setCart_itemprice(String cart_itemprice) {
Cart_item_list.cart_itemprice = cart_itemprice;
}
public static String getCart_collar() {
return cart_collar;
}
public static void setCart_collar(String cart_collar) {
Cart_item_list.cart_collar = cart_collar;
}
public static String getCart_cuffs() {
return cart_cuffs;
}
public static void setCart_cuffs(String cart_cuffs) {
Cart_item_list.cart_cuffs = cart_cuffs;
}
public static String getCart_placket() {
return cart_placket;
}
public static void setCart_placket(String cart_placket) {
Cart_item_list.cart_placket = cart_placket;
}
public static String getCart_pocket() {
return cart_pocket;
}
public static void setCart_pocket(String cart_pocket) {
Cart_item_list.cart_pocket = cart_pocket;
}
public static String getCart_fit() {
return cart_fit;
}
public static void setCart_fit(String cart_fit) {
Cart_item_list.cart_fit = cart_fit;
}
public static String getCart_initial() {
return cart_initial;
}
public static void setCart_initial(String cart_initial) {
Cart_item_list.cart_initial = cart_initial;
}
public Cart_item_list(int cart_itemimage, String cart_itemname, String cart_itemprice, String cart_collar, String cart_cuffs, String cart_placket, String cart_pocket, String cart_fit, String cart_initial) {
this.cart_itemimage = cart_itemimage;
this.cart_itemname = cart_itemname;
this.cart_itemprice = cart_itemprice;
this.cart_collar = cart_collar;
this.cart_cuffs = cart_cuffs;
this.cart_placket = cart_placket;
this.cart_pocket = cart_pocket;
this.cart_fit = cart_fit;
this.cart_initial = cart_initial;
}
}
it's the item list for listview adapter.
package com.example.yeong.shifendingzhi;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
public class Cart_item_adapter extends BaseAdapter {
Context context;
ArrayList<Cart_item_list> cart_item_listArrayList;
public Cart_item_adapter(Context context, ArrayList<Cart_item_list> cart_item_listArrayList) {
this.context = context;
this.cart_item_listArrayList = cart_item_listArrayList;
}
#Override
public int getCount() {
return cart_item_listArrayList.size();
}
#Override
public Object getItem(int i) {
return cart_item_listArrayList.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = LayoutInflater.from(context).inflate(R.layout.cart_listview, null);
ImageView selected_item_image = (ImageView) view.findViewById(R.id.selected_item_image);
TextView selected_cart_name = (TextView) view.findViewById(R.id.selected_cart_name);
TextView selected_cart_cuffs = (TextView) view.findViewById(R.id.selected_cart_cuffs);
TextView selected_cart_initial = (TextView) view.findViewById(R.id.selected_cart_initial);
TextView selected_cart_placket = (TextView) view.findViewById(R.id.selected_cart_placket);
TextView selected_cart_fit = (TextView) view.findViewById(R.id.selected_cart_fit);
TextView selected_cart_pocket = (TextView) view.findViewById(R.id.selected_cart_pocket);
TextView selected_cart_price = (TextView) view.findViewById(R.id.selected_cart_price);
TextView selected_cart_collar = (TextView) view.findViewById(R.id.selected_cart_collar);
selected_cart_name.setText(cart_item_listArrayList.get(i).getCart_itemname());
selected_cart_cuffs.setText(cart_item_listArrayList.get(i).getCart_cuffs());
selected_cart_initial.setText(cart_item_listArrayList.get(i).getCart_initial());
selected_cart_placket.setText(cart_item_listArrayList.get(i).getCart_placket());
selected_cart_fit.setText(cart_item_listArrayList.get(i).getCart_fit());
selected_cart_pocket.setText(cart_item_listArrayList.get(i).getCart_pocket());
selected_cart_price.setText(cart_item_listArrayList.get(i).getCart_itemprice());
selected_cart_collar.setText(cart_item_listArrayList.get(i).getCart_collar());
selected_item_image.setImageResource(cart_item_listArrayList.get(i).getCart_itemimage());
return view;
}
}
it's the listview adapter
I tried to create global variable arraylist, and shearched a lot, but all failed, singleton, using appllication.
Could you help me to make global arraylist for listview?
It helps me to save data temporary and chage the arraylist data on another activity.
Thanks.
I recommend the Paper library from https://github.com/pilgr/Paper
it is easy to configure and no need to setup any sql kind of connections , its like writing in a text file locally.
I used it and it is solid.
I mainly used it for storing the username and password for Remember Me in the login activity page:
if(ckbRemember.isChecked())
{
Paper.book().write(Common.USER_KEY,edtUsername.getText().toString());
Paper.book().write(Common.PWD_KEY,edtPassword.getText().toString());
}
and when you want to clear the data at any time and from any activity is like:
Paper.book().destroy();
if you want to store all of those values longer (e.g. for a few days or if the user closes your app) you can store those values in the shared preferences:
SharedPreferences spInstance = getSharedPreferences("my_identifier", Context.MODE_PRIVATE);
SharedPreferences.Editor spEditor = spInstance.edit();
spEditor.putString("key", "value");
spEditor.apply(); // Save the data
//Retrieve the data:
SharedPreferences spInstance = getSharedPreferences("my_identifier", Context.MODE_PRIVATE);
SharedPreferences.Editor spEditor = spInstance.edit();
String myString = spInstance.getString("key", "default-value");
That's it!
Use a simple POJO class. Make a java class that stores shirts attributes. Then declare a global arraylist with that class as its primitive type.
public class Shirt{
String cuffs;
String plackets;
String collars;
...
public String getCuff(){...}
public String getCollar(){...}
public void setCuff(){...}
public void setCollar(){...}
}
ArrayList<Shirt> shirts = new ArrayList<>();
Now you have to either store it in a SharedPreference or some database if you want it to persist. If you don't want storage but need a global context type variable, you can use Application class or a static variable maybe depending on whatever your use case is.
Edit: A simple example of Application class. Do remember to name the package in your Manifest.
Android provides several optionsto save persistent application data. The solution you choose depends on your specific needs, such as whether the data should be private, persistent and how much space your data requires. Take a look at Developers Guide
I have data in my firebase DB, everything works fine until I try to De-serialize the data.
Error: argument 1 has type io.realm.RealmList, got java.util.ArrayList
Here's my code:
DatabaseReference root = FirebaseDatabase.getInstance().
getReferenceFromUrl("https://swing-8792d.firebaseio.com/playlist");
Query playlistQuery = root.orderByKey().equalTo(key);
playlistQuery.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
Log.d("Child", child + "");
Playlist receivedPlaylist = child.getValue(Playlist.class);
Playlist playlist = new Playlist();
playlist.setCreatedBy(receivedPlaylist.getCreatedBy());
playlist.setName(receivedPlaylist.getName());
playlist.setMyMap(receivedPlaylist.getMyMap());
playlist.setQrKey(receivedPlaylist.getQrKey());
playlist.setCount(receivedPlaylist.getCount());
playlist.setId(receivedPlaylist.getId());
playlist.setTracks(receivedPlaylist.getTracks());
mPlaylist.add(playlist);
}
This is my POJO class:
#RealmClass
public class Playlist extends RealmObject {
String name;
Long id;
RealmList<Track> tracks;
Integer count;
String createdBy;
RealmList<UserMap> myMap;
String qrKey;
public RealmList<UserMap> getMyMap() {
return myMap;
}
public void setMyMap(RealmList<UserMap> myMap) {
this.myMap = myMap;
}
public Playlist(){}
public String getQrKey() {
return qrKey;
}
public void setQrKey(String qrKey) {
this.qrKey = qrKey;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public RealmList<Track> getTracks() {
return tracks;
}
public void setTracks(RealmList<Track> tracks) {
this.tracks = tracks;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}
If I try to de-serialize with Normal POJO class (i.e Removing Realm) it works fine.
Firebase won't work with classes that do not have default constructor or private variables i.e no public getter/setter.
A easier solution in your case would be to make a middleware class that is the same pojo just not extending RealmObject. Next initialise your RealmObject subclass using the values of the pojo.
Pseudo code
class SimplePojoPlaylist {
public String variable;
}
class Playlist extends RealmObject {
public String variable;
}
Then first cast into SimplePojoPlaylist
for (DataSnapshot child : dataSnapshot.getChildren()) {
SimplePojoPlaylist receivedPlaylist = child.getValue(SimplePojoPlaylist.class);
Playlist playList = new Playlist();
playList.variable = receivedPlaylist.variable;
}
RealmList is not a supported type for deserialization. Your database checks its structure and deduces that tracks should be an ArrayList. Then, when it tries to convert it, it finds that the types do not match.
Check this link from the docs:
Also, it is a good practice to make your objects immutable to avoid unwanted access and/or modifications.
Creating an empty object from scratch and then calling setter methods to define its state is not a very good pattern, because it can create a situation where an object is accessed before when its state is "broken".
If you need to create an object that is flexible, has a few mandatory fields and some optional, consider using the Builder pattern, although to do it you'd have to redesign your model.
wikipedia - Builder
If you don't need/want to use a builder, my advice is:
1) Make the empty constructor private and create another public one that requires all the fields.
2) Change your tracks field to be of type "List". Then, if you need the object to return a RealmList create another getter method such as tracksAsRealmList() that makes a RealmList out of the member list and returns it.
3) Make sure that the "Track" model has an empty private constructor, a public one with all of its parameters and that all of its fields are supported by firebase deserialization.
4) Unless strictly necessary, make your object fields private and set its value through a setter method.
I hope this helps you.
realm1.beginTransaction();
newuser tripnew = realm1.createObject(newuser.class);
int nid= (int)(realm.where(newuser.class).max("nid").intValue()+1);
tripnew.setNid(nid);
tripnew.setFrom(frominput.getText().toString());
tripnew.setTo(toinput.getText().toString());
tripnew.setDatejourney(dateinput.getText().toString());
realm1.commitTransaction();
updatetrip();
/// iam also use this code not working
realm.where(newuser.class).maximumInt("id_cp") + 1;
newuser.java//////
public class newuser extends RealmObject {
private String from,to,datejourney;
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public String getDatejourney() {
return datejourney;
}
public void setDatejourney(String datejourney) {
this.datejourney = datejourney;
}
}
It looks that your class doesn't have nid nor id_cp numeric field. Add int nid; field along with accessors and then realm.where(newuser.class).max("nid").intValue()+1 should work in most of the cases. However it will fail if there is no newuser instance in database yet. I use singleton factory for generating primary keys as a more generic solution.
There is a long discussion in Realm Git Hub if you need more context: Document how to set an auto increment id?
I am having a class EmployeeInfo as the following:
public class EmployeeInfo {
private int id; // Employee ID
private String name; // Employee Name
private int age;// Employee Age
public int getEmployeeID() {
return id;
}
public void setEmployeeID(int id) {
this.id = id;
}
public String getEmployeeName() {
return name;
}
public void setEmployeeName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age= age;
}
}
ArrayList<EmployeeInfo> employeeInfo object contains the emplyoyee info data for multiple employees.
I want to transfer the data( ArrayList employeeInfo ) from Activity1 to Activity2.
Is using Parcelable the only way to transfer the data from Activity1 to Activity2?
If not , what are the alternatives.
If yes ,kindly provide the prototype code of Parcelable along with the sample code on how to transfer the object data from Activity1 to Activity2.
Here is my implementation of Parceleble:
public class ProfileData implements Parcelable {
private int gender;
private String name;
private String birthDate;
public ProfileData(Parcel source) {
gender = source.readInt();
name = source.readString();
birthDate = source.readString();
}
public ProfileData(int dataGender, String dataName, String dataBDate) {
gender = dataGender;
name = dataName;
birthDate = dataBDate;
}
// Getters and Setters are here
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(gender);
out.writeString(name);
out.writeString(birthDate);
}
public static final Parcelable.Creator<ProfileData> CREATOR
= new Parcelable.Creator<ProfileData>() {
public ProfileData createFromParcel(Parcel in) {
return new ProfileData(in);
}
public ProfileData[] newArray(int size) {
return new ProfileData[size];
}
};
}
and how I transfer data:
Intent parcelIntent = new Intent().setClass(ActivityA.this, ActivityB.class);
ProfileData data = new ProfileData(profile.gender, profile.getFullName(), profile.birthDate);
parcelIntent.putExtra("profile_details", data);
startActivity(parcelIntent);
and take data:
Bundle data = getIntent().getExtras();
ProfileData profile = data.getParcelable("profile_details");
You can simply let your EmployeeInfo class implement Serializable. Or you can send data like this
intent.putExtra("id", employInfo.getEmployeeID());
intent.putExtra("name", employInfo.getEmployeeName());
intent.putExtra("age", employInfo.getAge());
If you need to transfer a list of your custom classes, i'd use the first approach. So you would be able to put entire list as Serializable.
However they said that everyone should use Parcelable instead because it's "way faster". Tbh, I'd never used it, because it needs more effort and I doubt somebody can realize the difference in speed in a regular application w/o a load of data sending via intent
Good question. Looking at the docs and doing armchair coding:
It may be possible to pass an object between Activities by calling putExtras(Bundle) and myBundle.putSerializable. The object and the entire object tree would need to implement serializable.
JAL
EDIT: The answer is yes:
It is possible to pass an immutable object between Activities by calling putExtras(Bundle) and myBundle.putSerializable. The object and the entire object tree would need to implement serializable. This is a basic tenet of Object Oriented Programming, passing of stateful messages.
First we create the immutable object by declaring a new class:
package jalcomputing.confusetext;
import java.io.Serializable;
/*
* Immutable messaging object to pass state from Activity Main to Activity ManageKeys
* No error checking
*/
public final class MainManageKeysMessage implements Serializable {
private static final long serialVersionUID = 1L;
public final int lengthPassword;
public final long timeExpire;
public final boolean isValidKey;
public final int timeoutType;
public MainManageKeysMessage(int lengthPassword, long timeExpire, boolean isValidKey, int timeoutType){
this.lengthPassword= lengthPassword;
this.timeExpire= timeExpire;
this.isValidKey= isValidKey;
this.timeoutType= timeoutType;
}
}
Then we create an immutable stateful instance of the class, a message, in the parent activity, and send it in an intent as in:
private void LaunchManageKeys() {
Intent i= new Intent(this, ManageKeys.class); // no param constructor
// push data (4)
MainManageKeysMessage message= new MainManageKeysMessage(lengthPassword,timeExpire,isValidKey,timeoutType);
Bundle b= new Bundle();
b.putSerializable("jalcomputing.confusetext.MainManageKeysMessage", message);
i.putExtras(b);
startActivityForResult(i,REQUEST_MANAGE_KEYS); // used for callback
}
Finally, we retrieve the object in the child activity.
try {
inMessage= (MainManageKeysMessage) getIntent().getSerializableExtra("jalcomputing.confusetext.MainManageKeysMessage");
lengthPassword= inMessage.lengthPassword;
timeoutType= inMessage.timeoutType;
isValidKey= inMessage.isValidKey;
timeExpire= inMessage.timeExpire;
} catch(Exception e){
lengthPassword= -1;
timeoutType= TIMEOUT_NEVER;
isValidKey= true;
timeExpire= LONG_YEAR_MILLIS;
}
Well there is another way to transfer an object.We can use application to transfer object and this is way is far better way in my opinion.
First of all create your custom application in your main package.
public class TestApplication extends Application {
private Object transferObj;
#Override
public void onCreate() {
super.onCreate();
// ACRA.init(this);
}
public Object getTransferObj() {
return transferObj;
}
public void setTransferObj(Object transferObj) {
this.transferObj = transferObj;
}
}
Now use setTransfer and get transfer methods to move abjects from one activity to other like:
To Transfer:
((TestApplication) activity.getApplication()).setTransferObj(Yous object);
ToRecieve:
Object obj=((TestApplication) activity.getApplication()).getTransferObj();
NOTE
Always remember to make entry of this application in manifest application tag:
<application
android:name=".TestApplication">
</application>
You can convert your object to jsonstring using Gson or Jakson and pass using intent as string and read the json in another activity.