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" />

  • 相关阅读:
    asp.net C# 实现阿里大鱼和云片网短信接口类
    asp.net C# 实现微信接口权限开发类
    asp.net C# 实现微信服务器配置
    php学习资料
    阿里云ECS升级OpenSSL记录
    Docker(十三):OpenStack部署Docker集群
    Docker(十二):Docker集群管理之Compose
    Docker(十一):Docker实战部署HTTPS的Tomcat站点
    Docker(十):Docker安全
    Docker(九):Docker容器卷插件
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429519.html
Copyright © 2011-2022 走看看