Is there any way make Snackbar persist among activity changes?

后端 未结 6 984
一整个雨季
一整个雨季 2020-12-13 04:25

Although Snackbar is beautiful, it doesn\'t persist when changing activities. This is a bummer in scenarios where I would like to confirm that a message was sen

6条回答
  •  庸人自扰
    2020-12-13 05:05

    UPDATE: See selected answer.

    The best solution to my question is using a Timer after the presenting the Snackbar and then in the run() method of the timer, starting the activity.

    Snackbar.show(); // Excluded make for brevity.
    
    Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                Intent chooseVideoIntent = new Intent(Intent.ACTION_GET_CONTENT); // Any type of content/file. Song, doc, video...
                chooseVideoIntent.setType("video/*");
                startActivityForResult(chooseVideoIntent, CHOOSE_VIDEO_REQUEST);
            }
        }, 2 * 1000);
    

    UPDATE: I found that by using findViewById(android.R.id.content) as the view in Snackbar.make() the Snackbar persists among fragment changes.

提交回复
热议问题