zoukankan      html  css  js  c++  java
  • 使用广播退出打开了多个activity的程序

    新建一个父类,在父类里动态注册广播,在这个广播的onrecive方法中结束当前activity,让每个activity继承这个父类,在要关闭的activity中发送广播,搞定

    下面是代码

    父类

    protected Myrecive myrecive;
        private class Myrecive extends BroadcastReceiver{
    
            @Override
            public void onReceive(Context context, Intent intent) {
                Log.v("sk",getLocalClassName());
                finish();
            }
        }
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main_activity4);
            myrecive = new Myrecive();
            IntentFilter _filter = new IntentFilter();
            _filter.addAction("com.xl.u323");
            registerReceiver(myrecive,_filter);
        }

    结束方法

        public void onClick(View v) {
                    Intent _intent = new Intent();
                    _intent.setAction("com.xl.u323");
                    sendBroadcast(_intent);
    }
    -----人若无名,则可专心练剑
  • 相关阅读:
    NFS共享储存
    Rsync服务
    企业集群架构概述
    定时任务
    开机启动流程
    进程管理(二)
    linux系统管理-进程管理
    RAID&LVM有关磁盘的故障
    gdisk分区及swap分区
    操作系统与磁盘管理
  • 原文地址:https://www.cnblogs.com/u3shadow/p/4316939.html
Copyright © 2011-2022 走看看