Search code examples
androidshareresume

android: drawing disappear after gmail


I am working on a drawing app where a user can share the picture in the drawing plate, and using the following code:

share = new Intent(Intent.ACTION_SEND);
share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment));
share.setType("image/png");
context.startActivity(Intent.createChooser(share, "Share Drawing"));

While the image can be successfully sent through whatsapp or gmail, etc, after finishing gmail action and returning back to the app, the drawing plate's drawing has disappeared.

Yet for whatsapp, the drawing would still be kept after sharing.

Does anybody know why and how could the drawing still remains in the drawView after gmail returns(after going to other app and resume)? Many thanks!


Solution

  • That will log your major lifecycle callbacks of your Activity, and then you can examine them in your logcat. You will probably have to save some information about your image in your onSaveInstanceState callback, and then restore it in your onCreate callback, assuming that your activity is indeed being destroyed and recreated, but that does seem to be the case.

        public class MyActivity exetends Activity {
             private final String TAG = "MyActivity";
    
             @Override
             protected void onCreate(Bundle savedInstanceState) {
                 Log.d(TAG, "onCreate")
             }
    
             @Override  
             protected void onStart() {
                 Log.d(TAG, "onStart")
             }
    
             @Override
             protected void onRestart() {
                 Log.d(TAG, "onRestart")
             }
    
             @Override
             protected void onResume() {
                 Log.d(TAG, "onResume")
             }
    
             @Override
             protected void onPause() {
                 Log.d(TAG, "onPause")
             }
    
             @Override
             protected void onStop() {
                 Log.d(TAG, "onStop")
             }
    
             @Override
             protected void onDestroy() {
                 Log.d(TAG, "onDestroy")
             }
             @Override
             protected void onSaveInstanceState(Bundle outBundle) {
                 Log.d(TAG, "onSaveInstanceState);
             }
    
    }