此服务中的代码我尝试将数据从服务发送到活动,但它不起作用,
public void onStart(Intent intent, int startId) { // TODO Auto-generated method stub super.onStart(intent, startId); Toast.makeText(this, "onstart()",Toast.LENGTH_SHORT).show(); String message = intent.getStringExtra("msg"); int ID = intent.getExtras().getInt("id"); Toast.makeText(getApplication(), message, Toast.LENGTH_LONG).show(); NotificationManager notificationmanager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationintent = new Intent(this, Details.class); notificationintent.putExtra("ID", ID); PendingIntent pendingintent = PendingIntent.getActivity(this,ID, notificationintent,0); int icon = R.drawable.ic_launcher; String tickerText = "you have a massege"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); String contentTitle = "Title"; String contentText = message; notification.setLatestEventInfo(this, contentTitle, contentText, pendingintent); notification.defaults = notification.DEFAULT_SOUND; notificationmanager.notify(ID, notification);
这是活动
Intent i = new Intent();
int num = i.getExtras().getInt("ID");
number.setText(num); // number is textview