1.使用Bundle进行传值
如:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,"default");
Intent intent = new Intent(this,MainActivity.class);
Bundle bundle = new Bundle();
bundle.putString("title",title);
bundle.putInt("progress",progress);
intent.putExtras(bundle);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
2.在活动的onResume方法中进行接收
@Override
protected void onResume() {
super.onResume();
Bundle bundle = getIntent().getExtras();
if(bundle!=null){
textStatus.setText(bundle.getString("title"));
progressBar.setProgress(bundle.getInt("progress"));
}
}