Hi. I'm trying to save a file in Activity.onPause method and sometimes
(I've fond it in Market stacktrace) View.getContext returns NULL. The
code:
public class MyActivity extends Activity {
...
@Override
protected void onPause() {
super.onPause();
surface.saveState();
}
...
}
class Surface extends SurfaceView {
...
public void saveState() {
try {
FileOutputStream fos =
getContext().openFileOutput(STATE_FILE,
Context.MODE_WORLD_READABLE);
bitmap.compress(CompressFormat.PNG, 100, fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
...
}
Link to the code:
http://github.com/wargoth/Sketcher/blob/master/src/org/sketcher/Surface.java#L139
Stacktrace:
...
dalvik.system.NativeStart.main(NativeStart.java:-2) Caused by:
java.lang.NullPointerException:
at org.sketcher.Surface.saveState(Surface.java:139) at
org.sketcher.Sketcher.onPause(Sketcher.java:101) at
android.app.Activity.performPause(Activity.java:3782) at
android.app.Instrumentation.callActivityOnPause(Instrumentation.java:
1190) at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2530) at android.app.ActivityThread.access$2200(ActivityThread.java:
119) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
1863) at android.os.Handler.dispatchMessage(Handler.java:99) at
android.os.Looper.loop(Looper.java:123) at
android.app.ActivityThread.main(ActivityThread.java:4363) at
java.lang.reflect.Method.invokeNative(Method.java:-2) at
java.lang.reflect.Method.invoke(Method.java:521) at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860) at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) at
dalvik.system.NativeStart.main(NativeStart.java:-2)
Any ideas? Thank you
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en