您的位置:首页 > 其它

Intent和PendingIntent

2011-05-04 17:53 253 查看
1.Intent是及时启动的,它随着它所在的Activity消失而消失。

 

Intent一般用作Activity、Service、BroadcastReceiver之间传递数据。

 

Intent reg = new Intent("com.hp.ui.ScreenHome");
reg.putExtra("method", "call");
reg.putExtra("number", phoneNum);
Main.this.sendBroadcast(reg);


 

 

2.PendingIntent是延时执行的Intent。

 

PendingIntent通常是由getActivity、getBroadcast、getService来获取实例的。当前的Activity不能马上启动它所包含的Intent,而由外部执行PendingIntent时,调用它所包含的Intent。

 

PendingIntent保存有当前App的Context,使得它可以赋予外部App一种能力,让外部App如同当前App一样执行PendingIntent中的Intent,即使当前App已经不存在了。

 

private Notification newNotification;
AlarmManager alarms;
PendingIntent alarmIntent;
String tickerText = "Here is a New TNews";
long when = System.currentTimeMillis();

newTNewsNotification = new Notification(R.drawable.icon, tickerText, when);
alarms = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
String ALARM_ACTION;
ALARM_ACTION = TNewsAlarmReceiver.ACTION_REFRESH_TNEWS_ALARM;
Intent intentToFire = new Intent(ALARM_ACTION);
alarmIntent = PendingIntent.getBroadcast(this, 0, intentToFire, 0);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  service action string