Catch Flash out-of-memory error in WebView?

前端 未结 2 1127
难免孤独
难免孤独 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: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.

提交回复
热议问题