알림을 처리하는 서비스가 있습니다. 내가 알림을 클릭하면 내가 액티비티 (NotificationActivity)에 Parcelable
객체를 보내고있다 :NullPointerException : 의도에서 파싱 가능 데이터 가져 오기
서비스 :
Intent destIntent = new Intent (this, NotificationActivity.class);
destIntent.putExtra ("notificationData", new ParcelableObject (mes));
PendingIntent contentIntent = PendingIntent.getActivity (this, 0, destIntent, 0);
NotificationActivity.java :
public class NotificationActivity extends Activity {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_notification);
// Always NullPointerException
ParcelableObject model = (ParcelableObject) (savedInstanceState.getParcelable ("notificationData"));
TextView content = (TextView)findViewById(R.id.content);
if (model == null) {
content.setText ("NULL");
} else {
content.setText (String.valueOf (model.dump()));
}
}
}
하지만 개체를 검색 할 때 NullPointerException이 계속 발생합니다.
편집 :
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_notification);
}
@Override
protected void onNewIntent (Intent intent) {
super.onNewIntent (intent);
setIntent (intent);
// Code not executed here
// Needed to move it to onResume()
// since according to the doc it comes after onNewIntent()
}
@Override
protected void onResume() {
super.onResume();
ParcelableObject model = (ParcelableObject) (getIntent().getParcelableExtra ("notificationData"));
Log.v ("MODEL :: ", model.dump().toString()); // NullPointerException
TextView content = (TextView)findViewById(R.id.content);
if (model == null) {
content.setText ("NULL");
} else {
content.setText (String.valueOf (model.dump()));
}
}
어떤 제안 : 제공된 답변을 따른 후 나는 그런 활동의 코드를 편집 한? 고맙습니다.
:) 제 편집을 확인해주세요. 당신이 말한대로 따라 가면서 여전히 NullPointerException을 얻습니다. – Copernic
destIntent .addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); 활동에 대한 의도를 만들 때 새로운 값을 전달하는지 확인하십시오. – Guardanis
당신이 옳았어요! : D는 이미 upvoted,하지만 난 분명히 대답을 받아 들일거야 :) 당신이 문제가 해결 된 이유를 설명해 주시겠습니까? 또한'onNewIntent()'의 코드가'setIntent()'와'onResume()'을 제외하고 실행되지 않는 이유는 무엇입니까? 고맙습니다. – Copernic