NoSuchMethod: isDestroyed ()

I just call isDestroyed () in Activity , and I got this ex:

04-09 03:08:12.692: E/AndroidRuntime(13234): FATAL EXCEPTION: main 04-09 03:08:12.692: E/AndroidRuntime(13234): java.lang.NoSuchMethodError: android.app.Activity.isDestroyed 04-09 03:08:12.692: E/AndroidRuntime(13234): at hu.illion.beentaps.util.ActivityKiller.killAllPastActivites(ActivityKiller.java:16) 04-09 03:08:12.692: E/AndroidRuntime(13234): at hu.illion.beentaps.MapBeenActivity$1.onClick(MapBeenActivity.java:75) 04-09 03:08:12.692: E/AndroidRuntime(13234): at android.view.View.performClick(View.java:4084) 04-09 03:08:12.692: E/AndroidRuntime(13234): at android.view.View$PerformClick.run(View.java:16966) 04-09 03:08:12.692: E/AndroidRuntime(13234): at android.os.Handler.handleCallback(Handler.java:615) 04-09 03:08:12.692: E/AndroidRuntime(13234): at android.os.Handler.dispatchMessage(Handler.java:92) 04-09 03:08:12.692: E/AndroidRuntime(13234): at android.os.Looper.loop(Looper.java:137) 04-09 03:08:12.692: E/AndroidRuntime(13234): at android.app.ActivityThread.main(ActivityThread.java:4931) 04-09 03:08:12.692: E/AndroidRuntime(13234): at java.lang.reflect.Method.invokeNative(Native Method) 04-09 03:08:12.692: E/AndroidRuntime(13234): at java.lang.reflect.Method.invoke(Method.java:511) 04-09 03:08:12.692: E/AndroidRuntime(13234): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 04-09 03:08:12.692: E/AndroidRuntime(13234): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558) 04-09 03:08:12.692: E/AndroidRuntime(13234): at dalvik.system.NativeStart.main(Native Method) 

I got activity on the list and I want to go through it and finish everything:

 for (Activity act : Variables.pastActivites) { try { Log.i("Killing: ", act.getLocalClassName()); if (!act.isDestroyed()) { act.overridePendingTransition(0, 0); act.finish(); } else { Variables.pastActivites.remove(act); } } catch (Exception ex) { Log.i("KillerAct: ", ex.toString()); } } 

I can even read the official documentation that there is a function called isDestroyed (). Now what?

+7
source share
3 answers

Activity.isDestroyed() is available starting from API level 17. If your application settings are for a lower API, you will get this Exception .

+20
source

You can write this to avoid the problem:

 if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) { if (!act.isDestroyed()) { act.overridePendingTransition(0, 0); act.finish(); } } 
+5
source

According to Activity.onDestroyed () , this is available in the 17th level API, and this is the latest version of Android 4.2 +

What version of Android are you trying to run this code on?

+3
source

All Articles