Android Handler.postDelayed(…)不会延迟Runnable

Android Handler.postDelayed(…)不会延迟Runnable,android,android-mediaplayer,runnable,android-handler,postdelayed,Android,Android Mediaplayer,Runnable,Android Handler,Postdelayed,我自己实现了一个OnCompletionListener,如下所示: public class SongEndCompletionListener implements OnCompletionListener{ String nextView; Context actualActivity; int stopTime; public SongEndCompletionListener(Context activity, String nextView, i

我自己实现了一个OnCompletionListener,如下所示:

public class SongEndCompletionListener  implements OnCompletionListener{

    String nextView;
    Context actualActivity;
    int stopTime;

    public SongEndCompletionListener(Context activity, String nextView, int time) {
        this.nextView = nextView;
        actualActivity = activity;
    }
    @Override
    public void onCompletion(MediaPlayer arg0) {


            Handler handler = new Handler(); 
            handler.postDelayed(new Runnable() { 
                 public void run() { 
                        try {
                     Intent stopplay;
                     stopplay = new Intent(actualActivity,Class.forName(nextView));
                     actualActivity.startActivity(stopplay);    
                 } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    } 
                 } 
            }, stopTime); 


    }
}
我希望它暂停stopTime秒,但实际上它所做的是,一旦音频文件结束,它就会跳转到下一个视图。 你能告诉我我错在哪里,或者我怎样才能以不同的方式延迟转换到另一项活动吗


感谢您的每一个提示

我知道你的处理程序为什么不延迟发布

这是因为您的停车时间为0。

您需要为“stopTime”设置一个值,否则将为0。 例如,要将Runnable延迟一秒钟:

stopTime = 1000; // milliseconds
或者使用您的构造函数:

public SongEndCompletionListener(Context activity, String nextView, int time) {
    this.nextView = nextView;
    actualActivity = activity;
    this.stopTime = time; // you forgot this
}

切换活动不是问题,这很好。它只是在“歌曲”结束时切换活动,而不是在停止播放后的stopTime毫秒。