android 在执行任务期间一直显示一个dialog
来源:互联网 发布:年龄大可做网络主播吗 编辑:程序博客网 时间:2024/04/29 11:02
在android 4.0源码的短信代码里面新增加了一个功能,能在加载图片的过程中一直显示一个dialog。
packages/apps/Mms/src/com.android.mms/ui/ComposeMessageActivity.java
定义它:
private void runAsyncWithDialog(final Runnable task, final int dialogStringId) { new ModalDialogAsyncTask(dialogStringId).execute(new Runnable[] {task}); }
创建一个异步任务:
private class ModalDialogAsyncTask extends AsyncTask<Runnable, Void, Void> { final int mDialogStringId; /** * Creates the Task with the specified string id to be shown in the dialog */ public ModalDialogAsyncTask(int dialogStringId) { this.mDialogStringId = dialogStringId; // lazy initialization of progress dialog for loading attachments if (mProgressDialog == null) { mProgressDialog = createProgressDialog(); } } /** * Initializes the progress dialog with its intended settings. */ private ProgressDialog createProgressDialog() { ProgressDialog dialog = new ProgressDialog(ComposeMessageActivity.this); dialog.setIndeterminate(true); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); dialog.setCanceledOnTouchOutside(false); dialog.setCancelable(false); dialog.setMessage(ComposeMessageActivity.this. getText(mDialogStringId)); return dialog; } /** * Activates a progress spinner on the UI. This assumes the UI has invoked this Task. */ @Override protected void onPreExecute() { // activate spinner after half a second mAttachmentEditorHandler.postDelayed(mShowProgressDialogRunnable, 500); } /** * Perform the specified Runnable tasks on a background thread */ @Override protected Void doInBackground(Runnable... params) { if (params != null) { try { for (int i = 0; i < params.length; i++) { params[i].run(); } } finally { // Cancel pending display of the progress bar if the image has finished loading. mAttachmentEditorHandler.removeCallbacks(mShowProgressDialogRunnable); } } return null; } /** * Deactivates the progress spinner on the UI. This assumes the UI has invoked this Task. */ @Override protected void onPostExecute(Void result) { if (mProgressDialog != null && mProgressDialog.isShowing()) { mProgressDialog.dismiss(); } } }
使用它:(参数:处理的任务,以及显示在dialog上的字符串的id)
runAsyncWithDialog(new Runnable() { public void run() { addAttachment(mimeType, uri, false); } }, R.string.adding_attachments_title);
- android 在执行任务期间一直显示一个dialog
- 一个PHP一直执行的例子 不会计划任务可以用这个 PHP+jquery前台动态显示数据库内容
- android 定时执行一个任务
- 自定义一个在底部显示的dialog
- android service中显示一个dialog
- quartz在job间隔期间内,保证上一个任务执行完后,再去执行下一个任务
- Android在Service中显示Dialog
- Android在Service中显示Dialog
- android开发 dialog显示在任意位置
- Android如何在service中显示Dialog
- Android Dialog种类大全,让Activity显示在另外一个Activity之上
- quartz在job间隔期间内,保证上一个任务执行完后,再去调度下一个任务
- 想在service中启动一个dialog,但是一直报错
- linux 技巧一:让任务一直执行
- DiaLog在底部显示
- 在查询分析器中执行update更新一个字段查询一直执行但不会成功
- RDPY:一个在RDP会话期间执行中间人攻击的工具
- 在winform中使用进度条显示任务的执行进度
- altium designer如何只显示一层,隐藏其他层显示
- 多字段模糊查询方法
- 润乾报表实现竖排文字
- UVa 10523 高精度
- YYXT之IT工作小记(十一)
- android 在执行任务期间一直显示一个dialog
- struts框架中 国际化支持应用步骤
- 大端和小端的问题
- struts2+session+cookie
- Cocos2D-X SimpleGame 如何移动一个cocos2d-x精灵 (2) ----版本cocos2d-2.0-x-2.0.3 .
- JS中location对象使用
- strut2拦截器详解
- UVa 321 - The New Villa
- 各种测试方法(蛮齐全的)