Android - openOptionsMenu doesn't work in onCreate

前端 未结 2 489
终归单人心
终归单人心 2020-12-16 19:33

Is there any other way to call openOptionsMenu after activity is displayed without using something like this:

new Handler().postDelayed(new Runnable() {
                  


        
2条回答
  •  情歌与酒
    2020-12-16 20:23

    My solution

    //Open menu manually from code 
        Timer timing = new Timer();
        timing.schedule(new TimerTask() {
    
                    /**
                     * {@inheritDoc}
                     */
                    @Override
                    public void run() {
    
                        runOnUiThread(new Runnable() {
    
                            @Override
                            public void run() {
                                openOptionsMenu();
                            }
                        });
    
                    }
                }, 1000);
    

提交回复
热议问题