Saving Parcelable data - android

I have a class which implements Parcelable, and could not implement Serializable because it contains some basic Android classes that I can not modify.
Some of the objects in this class are for example Location and PendingIntent (which are all conveniently Parcelable).
My problem is saving this information between the instances of my main Activity.
Currently, I'm holding a static reference to this class, which works well. But I assume that when I re-install the app, and probably when updates will come around, I won't be able to trust that this static member won't be re-initialized.
I tried to write this Parcelable to a file, but using marshall() is not always working (I'm getting Binder can't be marshalled error).
How can I safely save this information?
Thanks

Using static in your example leads to memory leaks and is not a good way to do anything.
I suggest using static only in 3 cases:
static final String or int - constants
on inner classes (so that they don't contain reference to outer class)
on util or in some cases (like CustomFragment.newInstance) factory methods
The question is why would you want to persist PendingIntent? Its usecase is for inter-process-communication.

I use a StateControl class to handle reading/writing to disc:
public class StateControl {
Context mContext;
Thread worker;
WriteObjectToFile writer;
// StateControl Constructor
public StateControl(Context context) {
mContext = context;
// Construct a writer to hold and save the data
writer = new WriteObjectToFile();
// Construct a worker thread to handle the writer
worker = new Thread(writer);
}// end of StateControl constructor
// Method to save the global data
public void saveObjectData(Object object, String key) {
if (object == null){
// I had a different action here
} else {
// Write the data to disc
writer.setParams(new WriteParams(object, key));
worker.run();
}
}// end of saveGlobalData method
// Method to read the Global Data
public Object readObjectData(String key){
Object returnData = (Object) readObjectFromFile(key);
if (returnData == null){
// I had a different action here
} else {
return returnData;
}
}// end of readGlobalData method
// Method to erase the Global data
public void clearObjectData(String key){
writer.setParams(new WriteParams(null, key));
worker.run();
}// end of clearGlobalData method
private class WriteObjectToFile implements Runnable {
WriteParams params;
public void setParams(WriteParams params) {
this.params = params;
}
public void run() {
writeObjectToFile(params.getObject(), params.getFilename());
}
private boolean writeObjectToFile(Object object, String filename) {
boolean success = true;
ObjectOutputStream objectOut = null;
try {
FileOutputStream fileOut = mContext.openFileOutput(filename, Activity.MODE_PRIVATE);
objectOut = new ObjectOutputStream(fileOut);
objectOut.writeObject(object);
fileOut.getFD().sync();
} catch (IOException e) {
success = false;
e.printStackTrace();
} finally {
if (objectOut != null) {
try {
objectOut.close();
} catch (IOException e) {
// do nothing
}
}// end of if
}// End of try/catch/finally block
return success;
}
}// end of writeObjectToFile method
private Object readObjectFromFile(String filename) {
ObjectInputStream objectIn = null;
Object object = null;
try {
FileInputStream fileIn = mContext.getApplicationContext().openFileInput(filename);
objectIn = new ObjectInputStream(fileIn);
object = objectIn.readObject();
} catch (FileNotFoundException e) {
// Do nothing
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
if (objectIn != null) {
try {
objectIn.close();
} catch (IOException e) {
// do nowt
}
}
}
return object;
}
private static class WriteParams {
Object object;
String filename;
public WriteParams(Object object, String filename) {
super();
this.object = object;
this.filename = filename;
}
public Object getObject() {
return object;
}
public String getFilename() {
return filename;
}
}
}
Then invoke the public methods to kick off the writing/reading. For this version, I also having it taking place in a separate thread, but you could modify that if you needed to.

Binder
Most developers will not implement this class directly, instead using
the aidl tool to describe the desired interface, having it generate
the appropriate Binder subclass.
from the official documentation
Do you need to store the Binder object with the rest of your object? Maybe you can save your object without the Binder instance, and re-create the Binder object with aidl after you restore the object

Related

What context should I pass to read from assets from another java class?

I have 2 Java files (CreateMyDb.java,ReadfromAssets.java).
In ReadfromAssets.java, I have the code below.
If I want to call ReadFileFromAssets method from CreateMyDb.java, How should I call,What is the context param I should pass? I am trying it make it work but in vain.
Thanks
public class ReadFromAssets extends Activity {
private static final String splitBy = ",";
private static int ID_Count = 6;
private static final String ObjName = "Question";
private static String NewObjName = "";
public void ReadFileFromAssets(Context myContext) {
//read from assets
myContext.getAssets();
AssetManager assetManager = myContext.getAssets();
InputStreamReader is = null;
try {
is = new InputStreamReader(assetManager.open("questions.csv"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(is);
try {
reader.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String line;
try {
while ((line = reader.readLine()) != null) {
NewObjName = ObjName+ID_Count;
String[] QDetails = line.split(splitBy);
Question NewObjName=new Question(QDetails[0],QDetails[1],QDetails[2],QDetails[3],QDetails[4],QDetails[5], QDetails[6]);
CreateMyDb db=new CreateMyDb (this);
db.AddToDB(NewObjName);
ID_Count = ID_Count+1;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//use assets however
}
}
In the CreateMyDb.java file, I am calling the same method as ,
private void addQuestions(){
ReadFromAssets ReadCsv = new ReadFromAssets();
ReadCsv.ReadFileFromAssets();//what should I pass as context here?
}
pass the context of that class where you are accessing this class method
ReadCsv.ReadFileFromAssets(CreateMyDb.this);
if the CreateMyDb class extend from activity or fragementactivity it obviously have the context of that activity too so pass the context of the class where you are accessing this thank you may be its help you
The most inmediate solution is pass the context of your activity to this class. Is that possible?
If you don't want to pass parameters, you can create an Application class to get the context of the application wherever you want.
public class ApplicationClass extends Application
{
private static ApplicationClass myAppClass;
#Override
public void onCreate()
{
super.onCreate();
myAppClass = this;
}
public static ApplicationClass getMyAppClass()
{
return myAppClass;
}
}
Then you must add the next line in the ManifestFile under the label
android:name="com.yourapp.ApplicationClass"
Now, you can call in you method ApplicationClass.getMyAppCLass().getAssets() without passing any context.
I must say that in this case the Application class is not used in the correct way. This class type is used to keep the application state, but is the only way I can think to do what you want without passing any parameter.

Is there a way to get information about each permission in android

Android provides the developer to declare the permission before an app can uses tools or hardware, I have created a class to store each permission's description like the permission name, nice name , description like what that permission does. Now is there anyway i can initialize each object programmatically, getting the information from http://developer.android.com/reference/android/Manifest.permission.html.
The code for the class is
package org.owasp.seraphimdroid.customclasses;
public class PermissionData {
private String permission;
private String permissionName;
private String description;
private String regularUseDescription;
private String maliciousUseDescription;
private int weight;
public PermissionData(String permission){
this.permission = permission;
setData();
}
private void setData(){
weight = 0;
}
//Getters and setter
public String getPermissionName() {
return permissionName;
}
public void setPermissionName(String permissionName) {
this.permissionName = permissionName;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public String getPermission() {
return permission;
}
public void setPermission(String permission) {
this.permission = permission;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getRegularUseDescription() {
return regularUseDescription;
}
public void setRegularUseDescription(String regularUseDescription) {
this.regularUseDescription = regularUseDescription;
}
public String getMaliciousUseDescription() {
return maliciousUseDescription;
}
public void setMaliciousUseDescription(String maliciousUseDescription) {
this.maliciousUseDescription = maliciousUseDescription;
}
}
Also should i store these objects as hashmap or in database?
These will mostly be used to display information in activity according to the permission.
Use the Context.check* methods (methods from the Context object that start with "check") for checking if a given permission is granted. See an example here.
Please note that permissions cannot be added at runtime.
The simplest ways to store your objects' data that I can think of at the moment are writing them to a database, serializing them into a file, or writing key-value pairs to SharedPreferences. It will depend on what you think is more appropriate. A hashmap has nothing to do with persistence; you may choose it as the approach to keep your data in memory and access it during the app's execution.
Training for Android developers has a section on writing key-value pairs and database persistence. If you wish to use serialization, the methods below might be useful:
private void _serializeObject(Object object, String fileName) {
String aboluteFilePath = getApplicationContext().getFilesDir().getPath() + File.separator + fileName;
try {
FileOutputStream fileOut = new FileOutputStream(absoluteFilePath);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(object);
out.close();
fileOut.close();
} catch (IOException e) {
Log.e(TAG, "Error while serializing data to " + absoluteFilePath, e);
}
}
private Object _deserializeObject(String fileName) {
Object object = null;
String absoluteFilePath = getApplicationContext().getFilesDir().getPath() + File.separator + fileName;
try {
FileInputStream fileIn = new FileInputStream(absoluteFilePath);
ObjectInputStream in = new ObjectInputStream(fileIn);
object = in.readObject();
in.close();
fileIn.close();
} catch (FileNotFoundException e) {
// You may want to ignore this exception as it will occur the first time the
// data is deserialized unless you make sure serialization occurs before it.
} catch (IOException e) {
Log.e(TAG, IOException.class.getSimpleName() + " while deserializing from " + absoluteFilePath, e);
} catch (ClassNotFoundException e) {
Log.e(TAG, ClassNotFoundException.class.getSimpleName() + " while deserializing from " + absoluteFilePath, e);
}
return object;
}

How do I set up my AsyncTask method if my images are being displayed in another class?

I have my method I'm calling the AsyncTask method from:
public static Drawable[] queryAppIcon() throws ParseException, IOException {
ParseQuery<ParseObject> query = ParseQuery.getQuery("AndroidStoreContent");
query.whereExists("appIcon");
List<ParseObject> ParseResult = query.find();
// initialize Drawable array
final Drawable[] appIconDrawable = new Drawable[ParseResult.size()];
for (int i = 0; i < ParseResult.size(); i++) {
ParseFile pf = (ParseFile) ParseResult.get(i).get("appIcon");
appIconDrawable[i] = DownloadImageTask.execute(pf);
}
return appIconDrawable;
}
the AsyncTask:
public class DownloadImageTask extends AsyncTask<ParseFile, Void, Drawable> {
ParseFile pf = null;
#Override
protected Drawable doInBackground(ParseFile... pf) {
this.pf = pf[0];
fetchDrawable(pf);
}
protected void onPostExecute() {
// do I do anything here?
}
public Drawable fetchDrawable(ParseFile pf) {
InputStream is;
try {
is = (InputStream) new URL(pf.getUrl()).getContent();
return Drawable.createFromStream(is,null);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
I know I'm supposed to have an onPostExecute, but the thing is the array of Drawable is going into another class for the ViewActivity:
// Get application image from Parse
Drawable[] appIconUrl = new Drawable[0];
try {
appIconUrl = ParseContent.queryAppIcon();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
for (int i = 0; i < appText.length; i++) {
OtherRowItem item = new OtherRowItem(appIconUrl[i], appText[i]);
otherRowItems.add(item);
}
otherSize = otherRowItems.size();
otherListView = (ListView) findViewById(R.id.other_games_list);
OtherListViewAdapter other_adapter = new OtherListViewAdapter(this,
R.layout.other_list_row, otherRowItems);
otherListView.setAdapter(other_adapter);
otherListView.setOnItemClickListener(this);
the ViewAdapter:
holder.imageView.setImageDrawable(otherRowItem.getAppIconUrl());
so I can't really display the image in the onPostExecute because it's being displayed in other classes.
The idea is pretty simple, I have a loop where I'm getting a ParseFile and then AsyncTask gets the contents of the ParseFile and creates a Drawable from it. I tested the method without the AsyncTask and it works (but takes a long, long time).
I'm getting two errors:
1.) With appIconDrawable[i] = DownloadImageTask.execute(pf);, I'm getting: Type mismatch: cannot convert from AsyncTask to Drawable.
2.) With fetchDrawable(pf);, I'm getting The method fetchDrawable(ParseFile) in the type ParseContent.DownloadImageTask is not applicable for the arguments (ParseFile[]).
On Post execute will receive the drawable you create in the background if you want to do anything on the UI thread with the Drawable, this is where to do it.
protected void onPostExecute(Drawable dr) { ... }
The following line
appIconDrawable[i] = DownloadImageTask.execute(pf);
causes an error because execute does not return the drawable from doInBackground as you are expecting - that drawable is pased into onPostExecute instead (always).
Your second issue is a simple one - you are passing in a whole array of items when you only want one item. If you actually only have one item then its just a case of passing in that element -
fetchDrawable(pf[0]);
Otherwise if you want the whole array processed, loop through and kick of multiple tasks.
My suggestion would be to pass in a callback when you create the AsyncTask which you can save as a member variable and which will call a method in the calling class from onPostExecute.
public interface OnDownloadCompleteListener {
void onDownloadComplete(Drawbale dr);
}
public class MyActivity extends Activity implements OnDownloadCompleteListener {
...
private void startDownloads() {
new DownloadImageTask(this).execute();
}
public onDownloadComplete(Drawable dr) {
//when we get here the drawable is loaded, so use it however we want
}
}
public class DownloadImageTask extends AsyncTask<ParseFile, Void, Drawable> {
private OnDownloadCompleteListener mListener;
DownloadImageTask(OnDownloadCompleteListener odcl) {
mListener = odcl;
}
...
public void onPostExecute(Drawable dr) {
mListener.onDownloadComplete(dr);
}
}

db4o on Android 3.0+ Issue

I'm having an issue with db4o on Android 3.0+ because it turns out that on the creation of the db4o database, it uses some of the network apis by default. (I stumbled upon this post: http://mavistechchannel.wordpress.com/2011/11/18/db4o-at-honeycomb-and-ice-cream-sandwich/ about it)
However, I've attempted to make the db creation requests async, but I think I'm running into an issue of calling the db before it's fully created as it locks the DB. (And I now get a locking error) Is there any way I can do this synchronous? or, at a minimum wait until it's been finished? Here's my db4o helper:
public class Db4oHelperAsync implements Constants{
private static final String USE_INTERNAL_MEMORY_FOR_DATABASE = "USE_INTERNAL_MEMORY_FOR_DATABASE";
private static ObjectContainer oc = null;
private Context context;
/**
* #param ctx
*/
public Db4oHelperAsync(Context ctx) {
context = ctx;
}
/**
* Create, open and close the database
*/
public ObjectContainer db() {
if (oc == null || oc.ext().isClosed()) {
if (Utilities.getPreferences(context).getBoolean(USE_INTERNAL_MEMORY_FOR_DATABASE, true)) {
new GetDbFromInternalMemory().execute();
} else {
new GetDbFromSDCard().execute();
}
return oc;
} else {
return oc;
}
}
/**
* Configure the behavior of the database
*/
private EmbeddedConfiguration dbConfig() throws IOException {
EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).objectField("name").indexed(true);
configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).cascadeOnUpdate(true);
configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).cascadeOnActivate(true);
configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).cascadeOnDelete(true);
configuration.common().objectClass(PersistentObjectWithoutCascadeOnDelete.class).objectField("name").indexed(true);
configuration.common().objectClass(PersistentObjectWithoutCascadeOnDelete.class).cascadeOnUpdate(true);
configuration.common().objectClass(PersistentObjectWithoutCascadeOnDelete.class).cascadeOnActivate(true);
return configuration;
}
/**
* Returns the path for the database location
*/
private String db4oDBFullPathInternal(Context ctx) {
return ctx.getDir("data", 0) + "/" + "testapp.db4o";
}
private String db4oDBFullPathSdCard(Context ctx) {
File path = new File(Environment.getExternalStorageDirectory(), ".testapp");
if (!path.exists()) {
path.mkdir();
}
return path + "/" + "testapp.db4o";
}
/**
* Closes the database
*/
public void close() {
if (oc != null)
oc.close();
}
private class GetDbFromInternalMemory extends AsyncTask<Void, Void, ObjectContainer>{
#Override
protected ObjectContainer doInBackground(Void... params) {
try {
ObjectContainer obj = Db4oEmbedded.openFile(dbConfig(), db4oDBFullPathInternal(context));
CLog.v("USING INTERNAL MEMORY FOR DATABASE");
return obj;
} catch (Exception ie) {
ie.printStackTrace();
CLog.e(Db4oHelper.class.getName(), ie.toString());
return null;
}
}
#Override
protected void onPostExecute(ObjectContainer result)
{
oc = result;
}
}
private class GetDbFromSDCard extends AsyncTask<Void, Void, ObjectContainer>{
#Override
protected ObjectContainer doInBackground(Void... params) {
try {
ObjectContainer obj = Db4oEmbedded.openFile(dbConfig(), db4oDBFullPathSdCard(context));
CLog.v("USING SDCARD FOR DATABASE");
SharedPreferences.Editor edit = Utilities.getPreferencesEditor(context);
edit.putBoolean(USE_INTERNAL_MEMORY_FOR_DATABASE, true);
edit.commit();
return obj;
} catch (Exception ie) {
ie.printStackTrace();
CLog.e(Db4oHelper.class.getName(), ie.toString());
return null;
}
}
#Override
protected void onPostExecute(ObjectContainer result)
{
oc = result;
}
}
}
Update: This db4o bug has been fixed. If you get the newest 8.1 bits the error should not occur and the workaround is obsolute:
You get a file-locked exception when trying to get the database? Right.
Well the issue is that you are not waiting for the async task to finish and just start a new one in case the Db4oHelperAsync.oc is null. You basically have to wait until the initialization has finished and only then use the Db4oHelperAsync.oc variable. So your in Java synchronization land.
For example you can do this: Synchronize the Db4oHelperAsync.oc access. When requesting the database wait until the variable is set. Now unfortunately I don't know the exact behavior of the async task. My guess is that it will run the .onPostExecute() method back on the main activity. That also means that you cannot just wait for it, because it would mean that you block the Activity-Thread and .onPostExecute() will never be executed.
Here's my draft of what I would try to do. I never executed nor compiled it. And it probably has synchronization issues. For example when the initialization fail it will just hang your applicaition on the .db() call, because it waits forever. So be very careful and try to improve it:
public class Db4oHelperAsync implements Constants{
private static final String USE_INTERNAL_MEMORY_FOR_DATABASE = "USE_INTERNAL_MEMORY_FOR_DATABASE";
private static ObjectContainer oc = null;
private static final Object lock = new Object();
private Context context;
/**
* #param ctx
*/
public Db4oHelperAsync(Context ctx) {
context = ctx;
}
/**
* Create, open and close the database
*/
public ObjectContainer db() {
synchronized(lock){
if (oc == null || oc.ext().isClosed()) {
if (Utilities.getPreferences(context).getBoolean(USE_INTERNAL_MEMORY_FOR_DATABASE, true)) {
new GetDbFromInternalMemory().start();
} else {
new GetDbFromSDCard().start();
}
while(oc==null){
this.wait()
}
return oc;
} else {
return oc;
}
}
}
/**
* Configure the behavior of the database
*/
private EmbeddedConfiguration dbConfig() throws IOException {
EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).objectField("name").indexed(true);
configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).cascadeOnUpdate(true);
configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).cascadeOnActivate(true);
configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).cascadeOnDelete(true);
configuration.common().objectClass(PersistentObjectWithoutCascadeOnDelete.class).objectField("name").indexed(true);
configuration.common().objectClass(PersistentObjectWithoutCascadeOnDelete.class).cascadeOnUpdate(true);
configuration.common().objectClass(PersistentObjectWithoutCascadeOnDelete.class).cascadeOnActivate(true);
return configuration;
}
/**
* Returns the path for the database location
*/
private String db4oDBFullPathInternal(Context ctx) {
return ctx.getDir("data", 0) + "/" + "testapp.db4o";
}
private String db4oDBFullPathSdCard(Context ctx) {
File path = new File(Environment.getExternalStorageDirectory(), ".testapp");
if (!path.exists()) {
path.mkdir();
}
return path + "/" + "testapp.db4o";
}
/**
* Closes the database
*/
public void close() {
synchronized(lock){
if (oc != null)
oc.close();
}
}
private class GetDbFromInternalMemory extends Thread{
#Override
protected void run() {
try {
ObjectContainer obj = Db4oEmbedded.openFile(dbConfig(), db4oDBFullPathInternal(context));
CLog.v("USING INTERNAL MEMORY FOR DATABASE");
synchronized(Db4oHelperAsync.lock){
Db4oHelperAsync.oc = obj;
Db4oHelperAsync.lock.notifyAll()
}
} catch (Exception ie) {
ie.printStackTrace();
CLog.e(Db4oHelper.class.getName(), ie.toString());
}
}
}
private class GetDbFromSDCard extends Thread{
#Override
protected void run() {
try {
ObjectContainer obj = Db4oEmbedded.openFile(dbConfig(), db4oDBFullPathSdCard(context));
CLog.v("USING SDCARD FOR DATABASE");
SharedPreferences.Editor edit = Utilities.getPreferencesEditor(context);
edit.putBoolean(USE_INTERNAL_MEMORY_FOR_DATABASE, true);
edit.commit();
synchronized(Db4oHelperAsync.lock){
Db4oHelperAsync.oc = obj;
Db4oHelperAsync.lock.notifyAll()
}
} catch (Exception ie) {
ie.printStackTrace();
CLog.e(Db4oHelper.class.getName(), ie.toString());
}
}
}
}
P.S. Added this problem as a bug to db4o: http://tracker.db4o.com/browse/COR-2269
Thanks for posting this issue, this is a serious fun-spoiler on Android.
When a new db4o database file is created, db4o generates it's unique internal signature by calling java.net.InetAddress.getLocalHost().getHostName(). Exceptions are not caught in this call. We will find a workaround for Android and post back here and to our forums when this is fixed.
Update Feb 9 2012:
The issue has been fixed and new builds are online.
http://community.versant.com/Blogs/db4o/tabid/197/entryid/1057/Default.aspx

java.io.NotSerializableException while writing Serializable object to external storage?

friends,
i am using following code to write Serializable object to external storage.
it throws me error java.io.NotSerializableException
even my object is serializable any one guide me what mistake am i doing?
public class MyClass implements Serializable
{
// other veriable stuff here...
public String title;
public String startTime;
public String endTime;
public boolean classEnabled;
public Context myContext;
public MyClass(Context context,String title, String startTime, boolean enable){
this.title = title;
this.startTime = startTime;
this.classEnabled = enable;
this.myContext = context;
}
public boolean saveObject(MyClass obj) {
final File suspend_f=new File(cacheDir, "test");
FileOutputStream fos = null;
ObjectOutputStream oos = null;
boolean keep = true;
try {
fos = new FileOutputStream(suspend_f);
oos = new ObjectOutputStream(fos);
oos.writeObject(obj); // exception throws here
}
catch (Exception e) {
keep = false;
}
finally {
try {
if (oos != null) oos.close();
if (fos != null) fos.close();
if (keep == false) suspend_f.delete();
}
catch (Exception e) { /* do nothing */ }
}
return keep;
}
}
and calling from activity class to save it
MyClass m= new MyClass(this, "hello", "abc", true);
boolean result =m.saveObject(m);
any help would be appreciated.
This fails due to the Context field in your class. Context objects are not serializable.
Per the Serializable documentation - "When traversing a graph, an object may be encountered that does not support the Serializable interface. In this case the NotSerializableException will be thrown and will identify the class of the non-serializable object."
You can either remove the Context field entirely, or apply the transient attribute to the Context field so that it is not serialized.
public class MyClass implements Serializable
{
...
public transient Context myContext;
...
}

Categories

Resources