4

My app launches the gallery to choose a photo. In the meantime, my app gets killed by the operating system, so that when I select the image my app needs to start up all over again.

NOTE: this is a transient issue. It often works just fine.

When it fails, there is nothing at all in the logs to indicate that a anything went wrong.

The gallery is launched in the usual way via Intent.ACTION_GET_CONTENT.

Why is my app being terminated? I can only assume it is a memory issue (caused by the Gallery app?), except that:

  • It happens with small images, too.

  • When it works successfully my app has no issues processing the images.

  • I'm using android:largeHeap="true". activityManager.getMemoryClass() = 256MB.

  • The issue happens more often when the debugger is connected.

  • A photo, even uncompressed, is probably no more than 30MB. At the time of launching the gallery, my system has 199MB available.

Even when the app restarts, the onActivityResult method is still called, so I can still resume the upload, but it makes for a very slow process and an awful user experience.

(Running Jellybean on Samsung Galaxy S3)

IanS
  • 1,459
  • 1
  • 18
  • 23
  • `my app needs to start up all over again`. What is so awfull on that? Are you using the instance state parameter of onCreate()? – greenapps Nov 01 '16 at 09:59
  • My app needs to fetch data over the internet every time the app starts up - therefore a restart during an image upload makes everything about 10 seconds slower than it ought to be. This is unacceptable user experience in my opinion. – IanS Nov 01 '16 at 10:47
  • And when you rotate your device? How do you handle that? You will not download all again i suppose? `Are you using the instance state parameter of onCreate()?` Why dont you answer that? – greenapps Nov 01 '16 at 11:06
  • Rotating the device does not trigger `onCreate()` or even `onRestoreInstanceState()`. Yes, I am using the instance state parameter, that is how I am able to resume the upload after a restart. I can not serialise the entire app state as I am running a webview which is making the network requests. – IanS Nov 01 '16 at 11:16

3 Answers3

0

try this bro, Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT);// startActivityForResult(Intent.createChooser(intent, "Select Picture"),123);

vyshak
  • 26
  • 2
  • How is this different from what I have already? I have tried with a chooser, but still seeing the same problem. – IanS Nov 01 '16 at 10:20
0

Try this

Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                intent.setType("image/*");
                startActivityForResult(
                        Intent.createChooser(intent, "Select File"),
                        SELECT_FILE);
Ragamai K
  • 3
  • 4
0

This works for me:-

 private static final int GALLERY_INTENT = 2;

Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("image/*"); startActivityForResult(intent, GALLERY_INTENT);

In ActivityResult

if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK && data != null) { //do something }

And make sure you have added these in manifest file

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

PraKi
  • 13
  • 6
  • I have done all of that. There is nothing missing from my code, as it often works just fine. – IanS Nov 01 '16 at 10:55