FLAG_NOT_FOCUSABLE on activity

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    }
}

if i press button back, app is stunt on 10-15 seconds. in log write:

D/ANRAppManager: !!! It is not under singleton mode, U can't use it. !!!
I/dalvikvm: threadid=3: reacting to signal 3
D/dalvikvm: dump native stack for : main
D/dalvikvm: unwind backtrace
D/dalvikvm: get native symbol
D/dalvikvm: format backtrace line
D/dalvikvm: get native done
D/dalvikvm: dump native stack for : Thread-7090
D/dalvikvm: unwind backtrace
D/dalvikvm: get native symbol
D/dalvikvm: format backtrace line
D/dalvikvm: get native done
D/dalvikvm: dump native stack for : Binder_2
D/dalvikvm: unwind backtrace
D/dalvikvm: get native symbol
D/dalvikvm: format backtrace line
D/dalvikvm: get native done
D/dalvikvm: dump native stack for : Binder_1
D/dalvikvm: unwind backtrace
D/dalvikvm: get native symbol
D/dalvikvm: format backtrace line
D/dalvikvm: get native done
D/dalvikvm: dump native stack for : Compiler
D/dalvikvm: unwind backtrace
D/dalvikvm: get native symbol
D/dalvikvm: format backtrace line
D/dalvikvm: get native done
D/dalvikvm: dump native stack for : JDWP
D/dalvikvm: unwind backtrace
D/dalvikvm: get native symbol
D/dalvikvm: format backtrace line
D/dalvikvm: get native done
D/dalvikvm: dump native stack for : GC
D/dalvikvm: unwind backtrace
D/dalvikvm: get native symbol
D/dalvikvm: format backtrace line
D/dalvikvm: get native done
D/dalvikvm: Prepare stack traces for '/data/anr/traces.txt' done
I/dalvikvm: Wrote stack traces to '/data/anr/traces.txt'

and app crash.

in this file /data/anr/traces.txt: https://pastebin.com/J6qdJjU7

I'm doing something like AppLocker. I want that when the button is pressed back, the activity(app) that is behind this activity closes, and the activity that is behind my activity of another application.

any ways to do this functional, not necessary with FLAG_NOT_FOCUSABLE. how it make?

1 answer

  • answered 2018-05-16 04:41 GParekar

    I Hope this will work for you.

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    

    Call this line before setContentView(R.layout.activity_main);