我想开始一项新活动,但仅在显示我的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();


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

谢谢!

最佳答案

我解决如下。

在名为“ TestActivity”的活动中,我调用了:

showCroutonMsgThenGoToActivity(text);


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

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();
}

07-26 01:46