Catch Flash out-of-memory error in WebView?

前端 未结 2 1126
难免孤独
难免孤独 2021-01-15 10:12

When loading certain .swf files into a WebView, a split second after the flash file begins to be displayed, my app closes with a Signal 11

相关标签:
2条回答
  • 2021-01-15 10:30

    I think you need to handle the kill even in onPause()

    On the link below you would see a table of all the methods in activity that you can override. It has one column called killable. Which indicates can this methods be killed. As onDestroy() is a killable methods there is a chance that it may not be called. But onPause() is not killable so u can handle you logic of saving state or anything else here. Activity

    0 讨论(0)
  • 2021-01-15 10:37

    An alternative solution could be to use a background task or service to monitor the memory usage on the device, if the system tells you that you're on low memory, kill the flash activity.

    To know if you are on low memory you can use this code:

    ActivityManager activityManager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
    MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); 
    activityManager.getMemoryInfo(memoryInfo);
    
    boolean onLowMemory = memoryInfo.lowMemory;
    

    Or you can check the available memory using memoryInfo.availMem, if it's too low (close to memoryInfo.threshold) kill your activity before the exception.

    0 讨论(0)
提交回复
热议问题