zoukankan      html  css  js  c++  java
  • Service(三)

    Activity类:

    public class ServiceUI extends Activity {

            

            private mServiceUIReceiver mReceiver = null;

            private TextView tv_msg = null;

            private ProgressDialog mProgressDialog = null;

            private Intent intent = null;

            

        /** Called when the activity is first created. */

        @Override

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            

            tv_msg = (TextView)findViewById(R.id.tv_msg);

            

            //注册BroadcastReceiver

            mReceiver = new mServiceUIReceiver();

            IntentFilter mFilter = new IntentFilter(ServiceUIService.SERVICEUI_SERVICE);

            registerReceiver(mReceiver, mFilter);

            

            //开启服务

            intent = new Intent();

            intent.setClass(this, ServiceUIService.class);

            startService(intent);

            

            //初始化ProgressDialog

            mProgressDialog = new ProgressDialog(this);

            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

            mProgressDialog.setMessage("正在启动服务...");

            mProgressDialog.setCancelable(false);

        }

        

        @Override

        protected void onDestroy() {

                unregisterReceiver(mReceiver);

                stopService(intent);            

                super.onDestroy();

        }

        

        private class mServiceUIReceiver extends BroadcastReceiver{

                //广播接受数据

                    @Override

                    public void onReceive(Context context, Intent intent) {

                            

                            Bundle bundle = intent.getExtras();

                            int pd_value = bundle.getInt("ProgressDialogValue");

                            String pd_data=bundle.getString("data");

                            if(pd_value==0){

                                    //显示ProgressDialog

                                    mProgressDialog.show();

                            }

                            if(pd_value==100){

                                    //销毁ProgressDialog

                                    mProgressDialog.dismiss();

                                    tv_msg.setTextSize(25f);

                                    tv_msg.setText(pd_data);

                                    

                            }

                    }

        }

    }

    Manifest代码清单:

    <service android:name=".ServiceUIService" android:enabled="true" />

  • 相关阅读:
    TSQL 中游标应用示例
    [转]浅谈数据库设计技巧(上)、(下)
    ASP.NET页面打印技术的总结(转)
    深入理解RIA(转)
    三层架构的bussiness层没用?
    ASP.NET中常用的26个优化性能方法(转)
    基于MapX的GIS动态操作与实现
    web项目经理手册项目经理的工作内容(转)
    ASP.NET中上传文件到数据库
    学习.net中I/O的心得第一篇 初探I/O(转)
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429519.html
Copyright © 2011-2022 走看看