Android:如何在Crouton onDisplayed()上使用回调

MDT*_*MDT 1 java android callback android-lifecycle crouton

我想开始一项新的活动,但仅在我的Crouton展示之后.

我想使用Crouton的onDisplayed()函数 https://github.com/keyboardsurfer/Crouton/blob/master/library/src/de/keyboardsurfer/android/widget/crouton/LifecycleCallback.java

然后按如下方式调用我的活动

Intent i = new Intent(this, MyNewActivity.class);
startActivity(i);
finish();
Run Code Online (Sandbox Code Playgroud)

我一直在尝试创建我的回调函数,但到目前为止没有运气...

谢谢!

MDT*_*MDT 5

我解决了如下问题.

在我的名为"TestActivity"的Activity中,我打电话给:

showCroutonMsgThenGoToActivity(text);
Run Code Online (Sandbox Code Playgroud)

在同一个类中,我添加了以下功能:

public void showCroutonMsgThenGoToActivity(String text) {
    Crouton toShow = null;

    LifecycleCallback myCallback = new LifecycleCallback() {
        public void onDisplayed() {
            // do nothing
        }

        // Will be called when your {@link Crouton} has been removed.
        public void onRemoved() {
            skipToNextActivity(MyNewActivity.class);
        }
    };


        //create config 
        Configuration myConfig = new Configuration.Builder().
                setDuration(1000)  
                .build();

        //create style
        Style myStyle = new Style.Builder().setConfiguration(myConfig)
                .setBackgroundColor(R.color.green) //check your color!
                .build();

        //apply my custom stile
        toShow = Crouton.makeText(TestActivity.this, text, myStyle);

    toShow.setLifecycleCallback(myCallback);
    toShow.show();
}


private void skipToNextActivity(Class c) {
    // go to next activity
    Intent i = new Intent(this, c);
    startActivity(i);
    finish();
}
Run Code Online (Sandbox Code Playgroud)