Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethod: isDestroyed()

I simply call isDestroyed() on an 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 activites in a List, and i want to iterate through it and finish all of them:

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 named isDestroyed(). What now?

like image 449
Adam Varhegyi Avatar asked Apr 09 '13 01:04

Adam Varhegyi


1 Answers

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

like image 85
jprofitt Avatar answered Oct 20 '22 16:10

jprofitt