`

【Service & BroadcastReceiver相关】

阅读更多
android开发中如何实现开机自启动
http://gundumw100.iteye.com/blog/906188

监听应用程序安装和卸载
http://zhangkun716717-126-com.iteye.com/blog/1192479

使用service定期执行一个服务
http://gundumw100.iteye.com/blog/896880

利用BroadcastReceiver监听短信
http://gundumw100.iteye.com/blog/875951

使用Service和BroadcastReceiver实时监听网络状态
http://gundumw100.iteye.com/blog/1732865


Service里面启动Activity和Alertdialog
启动Activity源码:(记得要加上Intent.FLAG_ACTIVITY_NEW_TASK)
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
intent.setClass(getApplicationContext(),FileBrowserActivity.class);
startActivity(intent);

原因:如果一个外部的Activity Context调用startActivity方法,那么,Intent对象必须包含 FLAG_ACTIVITY_NEW_TASK标志,这是因为,待创建的Activity并没有从一个已经存在的Activity启动(任务栈中并没有此Activity),它并没有已经存在的任务,因此它需要被放置在自己独立的任务中(也就是在任务栈中新建一个任务)。

启动AlertDialog源码:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("是否接受文件?")
.setPositiveButton("是", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                }).setNegativeButton("否", new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });

AlertDialog ad = builder.create();
//ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); //系统中关机对话框就是这个属性 
ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
ad.setCanceledOnTouchOutside(false);                                   //点击外面区域不会让dialog消失
ad.show();


还要加上权限:<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

Service中显示一个Dialog 或者通过WindowManage显示View
http://www.cnblogs.com/0616--ataozhijia/p/4145313.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics