简体   繁体   English

Android-如何执行操作,直到处理程序未完成延迟

[英]Android - How to perform an action until a Handler doesn't complete the delay

I have an app where the user can rate a post with a like/dislike. 我有一个应用程序,用户可以在其中对喜欢/不喜欢的帖子评分。 After that I show a view with the autor of the post for a second and update the content with another article. 之后,我与帖子的指导者展示了一下视图,并用另一篇文章更新了内容。

The code that I am using right now for this delay is: 我现在为此延迟使用的代码是:

Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    nextFragment();
                                }
                            }, 1000);

I would like to provide a share functionality after the user rate the article, that will appear just for this second. 我想在用户对文章进行评分之后提供共享功能,此功能将仅在第二秒出现。 But I don't have any ideas of how to do it. 但是我对如何做到没有任何想法。 How can I show this view with the author for a second, and in case of the user click the share button, I perform the share action and comeback to the next article after that? 如何与作者保持一秒钟的距离,如果用户单击共享按钮,我将执行共享操作并在此之后返回下一篇文章?

Thanks! 谢谢!

Well why don't you just do your action before starting the handler, and cancel that action when the handler completes? 那么,为什么不只是在启动处理程序之前执行操作 ,而在处理程序完成时取消该操作呢? Example: 例:

final ProgressDialog dialog = new ProgressDialog(this);
dialog.setTitle("Something something");
dialog.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        dialog.dismiss();
        nextFragment();
    }
}, 1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在android中延迟操作(为什么处理程序不起作用?) - How to delay operation in android(why doesn't handler work?) 随机时间延迟后如何执行动作? -安卓 - How to perform an action after a Random Time Delay? - Android Android通知完成后如何执行操作? - How do I perform an action when an Android Notification is complete? 如何将 Android 房间加载延迟到活动和提示完成之后? - How do I delay Android Room loading until after activity and prompts complete? 在doInBackground()完成之前,ProgressDialog不会显示 - ProgressDialog doesn't show until doInBackground() is complete 我希望Android进度对话框一直显示在屏幕上,直到新活动的功能完成但不起作用 - I want Android progress dialog to stay on screen until function on new activity is complete but doesn't work Android recyclerview 不会立即观察数据,直到我刷新或在短时间内观察使用处理程序 - Android recyclerview doesn't observe data immediately until I refresh or observe using handler after short time 将android中的动作延迟到上一个动作完成为止 - Delay actions in android until a previous action has completed DownloadManager没有收到下载完成操作 - DownloadManager doesn't receive download complete action 如何在Android活动中执行此操作? - How to perform this action in Android Activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM