ANDROID+后台Task+Notification++Intent+实例对象的配置
来源:互联网 发布:virtualbox ubuntu 编辑:程序博客网 时间:2024/05/16 10:50
相信Android的开发着 对于后台Task的开发都碰的问题吧。 针对今天开发的时候碰到的问题和解决的方法, 分享下。
1.Intent 实例对象的配置
//----Notification 后台task intent 设置
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClass(this, XmeAct.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
//----Notification 后台task intent 设置----end---
setClass 中.class 设置为自己要返回的 activity的名字。
2. 对于 Android Home 键 的监听
方法(1) . 步骤a. @Override onAttachedToWindow() 方法, 使得Home 键功能被屏蔽
@Override
public void onAttachedToWindow() {
// TODO Auto-generated method stub
System.out.println("--onAttachedToWindow---");
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
步骤b. @Override onKeyDown() 方法, 进一步自定义对 Home键进行处理
//---判断Home 键
if(KeyEvent.KEYCODE_HOME==keyCode)
{
//-----自定义Home 键处理
//-----跳转回Android 主界面(和原来Home键是一样的功能)
Intent i= new Intent(Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
return super.onKeyDown(keyCode, event);
}
方法2. 根据Home 键的执行 过程中处理 Notification
Home 键的执行过程(不多说了,上网查下。笔者也不是很清楚)
笔者 复写 onUserLeaveHint() 方法。 不管怎么说 点击Home键之后 一定会执行
onUserLeaveHint()方法。在onUserLeaveHint()下 添加一个Notification 。
转载请注明出处:http://blog.csdn.net/lestat1225/article/details/6872087
- ANDROID+后台Task+Notification++Intent+实例对象的配置
- Android Task 有关的 Intent 对象中设置的 Flag
- android Notification的实例与Notification API
- Android 的notification 的intent 传值
- Android的Notification实例介绍
- 跟 Task 有关的 Intent对象中设置的Flag
- 与 TASK 有关的 INTENT对象中设置的FLAG
- 跟 Task 有关的 Intent对象中设置的Flag
- 跟 Task 有关的 Intent对象中内置的Flag
- 跟 Task 有关的 Intent对象中内置的Flag
- android的Intent用法实例
- android的Intent用法实例
- Android 如何设置 Notification 中PendingIntent 的 Intent
- android Intent 对象的传递
- Android的Intent&IntentFilter Intent属性及Intent-filter配置
- Android Notification实例理解
- Android Notification实例理解
- android Notification 实例
- 谁是世界上最大的雇主?
- 终于知道“回车”和“换行”的意思了+-_-|||
- 来CSDN后的first blog
- 什么是软件的α版、β版
- Java+6+JVM参数选项大全(中文版)
- ANDROID+后台Task+Notification++Intent+实例对象的配置
- 本账号不再维护,找我请移步。。。
- D语言之路-第1篇 库函数之争
- Combine algorithm
- 贝塞尔曲线算法的Javascript实现
- ImageButton去边框&Button或者ImageButton的背景透明
- Javascript输出1到100的整数,不用循环,不用递归
- An Introduction to Data Mining
- #XML之路#XSD——complexType