他人のアプリの暗黙的 Intent を受け取るアプリを開発中しています。
Intent を受け取り、アプリを落とさないまま遷移元のアプリから再度 Intent 呼び出しを繰り返すと OutOfMemoryError が発生します。(戻るボタンを押すとひとつ前の状態の画面に戻ります。OutOfMemoryError が発生するころには200MB~300MBほどになっている模様…?)
明示的 Intent の場合はメモリを破棄してから遷移することで解決できるようですが、今回の暗黙的 Intent の場合は遷移元が他人のアプリなのでどう対処するのかわからず質問させていただきました。
それと後回しで大丈夫なのですが、
遷移元(他人のアプリ)がどのような内容で暗黙的 Intent 呼び出しをしてるのか調べる方法はありませんか?
AndroidアプリやAndroid Studioの機能で
ブラウザ等が表示されていたのでとりあえず
<intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> </intent-filter>
で受け取っているのですが、できれば範囲を狭くといいますか…、細かく指定したいです。
ログを追記します。
09-26 16:21:39.588 21464-21728/com.sample.teratest E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2 Process: com.sample.teratest, PID: 21464 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:309) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.OutOfMemoryError: Failed to allocate a 518412 byte allocation with 409320 free bytes and 399KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:635) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:611) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:649) at com.sample.teratest.AsyncTaskHttpRequest.doInBackground(AsyncTaskHttpRequest.java:44) at com.sample.teratest.AsyncTaskHttpRequest.doInBackground(AsyncTaskHttpRequest.java:21) at android.os.AsyncTask$2.call(AsyncTask.java:295) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)
… 09-26 16:21:40.020 21464-21730/com.sample.teratest I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 191MB/192MB, paused 563us total 48.241ms 09-26 16:21:40.020 21464-21464/com.sample.teratest I/art: WaitForGcToComplete blocked for 43.241ms for cause Alloc 09-26 16:21:40.020 21464-21464/com.sample.teratest I/art: Starting a blocking GC Alloc 09-26 16:21:40.065 21464-21730/com.sample.teratest W/art: Suspending all threads took: 36.464ms 09-26 16:21:40.067 21464-21464/com.sample.teratest I/art: Clamp target GC heap from 207MB to 192MB 09-26 16:21:40.067 21464-21464/com.sample.teratest I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 191MB/192MB, paused 500us total 45.333ms 09-26 16:21:40.068 21464-21464/com.sample.teratest W/art: Throwing OutOfMemoryError "Failed to allocate a 518412 byte allocation with 386344 free bytes and 377KB until OOM" 09-26 16:21:40.068 21464-21464/com.sample.teratest I/art: Starting a blocking GC Alloc 09-26 16:21:40.069 21464-21464/com.sample.teratest I/art: Starting a blocking GC Alloc 09-26 16:21:40.071 21464-21730/com.sample.teratest I/art: Forcing collection of SoftReferences for 506KB allocation 09-26 16:21:40.071 21464-21730/com.sample.teratest I/art: Waiting for a blocking GC Alloc 09-26 16:21:40.073 21464-21730/com.sample.teratest I/art: Starting a blocking GC Alloc 09-26 16:21:40.076 21464-21464/com.sample.teratest I/art: Waiting for a blocking GC Alloc 09-26 16:21:40.146 21464-21730/com.sample.teratest I/art: Clamp target GC heap from 207MB to 192MB 09-26 16:21:40.146 21464-21730/com.sample.teratest I/art: Alloc concurrent mark sweep GC freed 4(128B) AllocSpace objects, 0(0B) LOS objects, 0% free, 191MB/192MB, paused 2.941ms total 72.499ms 09-26 16:21:40.146 21464-21464/com.sample.teratest I/art: WaitForGcToComplete blocked for 70.111ms for cause Alloc 09-26 16:21:40.146 21464-21464/com.sample.teratest I/art: Starting a blocking GC Alloc 09-26 16:21:40.191 21464-21730/com.sample.teratest W/art: Suspending all threads took: 37.242ms 09-26 16:21:40.196 21464-21464/com.sample.teratest I/art: Clamp target GC heap from 207MB to 192MB 09-26 16:21:40.196 21464-21464/com.sample.teratest I/art: Alloc partial concurrent mark sweep GC freed 2(64B) AllocSpace objects, 0(0B) LOS objects, 0% free, 191MB/192MB, paused 561us total 44.993ms 09-26 16:21:40.197 21464-21730/com.sample.teratest W/art: Throwing OutOfMemoryError "Failed to allocate a 518412 byte allocation with 386312 free bytes and 377KB until OOM" 09-26 16:21:40.200 21464-21464/com.sample.teratest I/art: Starting a blocking GC Alloc 09-26 16:21:40.202 21464-21730/com.sample.teratest I/art: Waiting for a blocking GC Alloc 09-26 16:21:40.245 21464-21464/com.sample.teratest I/art: Clamp target GC heap from 207MB to 192MB 09-26 16:21:40.245 21464-21464/com.sample.teratest I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 191MB/192MB, paused 565us total 44.183ms 09-26 16:21:40.246 21464-21730/com.sample.teratest I/art: WaitForGcToComplete blocked for 44.864ms for cause Alloc 09-26 16:21:40.246 21464-21730/com.sample.teratest I/art: Starting a blocking GC Alloc 09-26 16:21:40.247 21464-21730/com.sample.teratest I/art: Starting a blocking GC Alloc 09-26 16:21:40.249 21464-21464/com.sample.teratest I/art: Forcing collection of SoftReferences for 506KB allocation 09-26 16:21:40.249 21464-21464/com.sample.teratest I/art: Waiting for a blocking GC Alloc 09-26 16:21:40.254 21464-21730/com.sample.teratest I/art: Alloc sticky concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 191MB/192MB, paused 619us total 7.366ms 09-26 16:21:40.254 21464-21464/com.sample.teratest I/art: WaitForGcToComplete blocked for 5.086ms for cause Alloc 09-26 16:21:40.254 21464-21464/com.sample.teratest I/art: Starting a blocking GC Alloc 09-26 16:21:40.295 21464-21730/com.sample.teratest W/art: Suspending all threads took: 36.857ms 09-26 16:21:40.299 21464-21464/com.sample.teratest I/art: Clamp target GC heap from 207MB to 192MB 09-26 16:21:40.299 21464-21464/com.sample.teratest I/art: Alloc concurrent mark sweep GC freed 9(544B) AllocSpace objects, 0(0B) LOS objects, 0% free, 191MB/192MB, paused 3.201ms total 44.447ms 09-26 16:21:40.299 21464-21730/com.sample.teratest I/art: Waiting for a blocking GC Alloc 09-26 16:21:40.301 21464-21730/com.sample.teratest I/art: Starting a blocking GC Alloc 09-26 16:21:40.302 21464-21464/com.sample.teratest W/art: Throwing OutOfMemoryError "Failed to allocate a 518412 byte allocation with 386536 free bytes and 377KB until OOM" 09-26 16:21:40.303 21464-21464/com.sample.teratest D/AndroidRuntime: Shutting down VM 09-26 16:21:40.303 21464-21464/com.sample.teratest I/Process: Sending signal. PID: 21464 SIG: 9