Android - Forcing ANR for testing purpose

后端 未结 6 1113
花落未央
花落未央 2020-12-16 03:42

Why i can\'t force Android ANR with this code? No log messages or pop up. The application is just launched lazily.

[UPDATE]

I can\'t get it even sleeping a V

6条回答
  •  春和景丽
    2020-12-16 04:31

    Try using:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        int a=0;
        while(true) {
            a++;
        }       
    }
    

    Your code probably didn't work because it got setup too early, and the Activity probably wasn't fully initialized and created yet. With the above code, launch the activity and touch/swipe on the screen and wait for the ANR dialog to popup.

提交回复
热议问题