लौटाता है मैं एक अधिसूचना और घटना onCreate
के माध्यम से एक गतिविधि चलाने की कोशिश कर रहा हूं, मैं "रीडायरेक्ट" करना चाहता हूं। इसके लिए Intent
कक्षा में जानकारी पर एक विचार जोड़ें। एक महत्वपूर्ण विशेषता यह है कि अधिसूचना उत्पन्न करने वाली कक्षा एक सेवा के माध्यम से की जाती है। मैं android.app.Application
वर्ग द्वारा प्रदान की गई getApplicationContext
विधि से संदर्भ पुनर्प्राप्त करता हूं। जब भी मैं विधि getExtras()
कॉल करता हूं null
लौटा रहा है। मैं क्या गलत कर रहा हूं?Intent.getExtras() हमेशा शून्य
public class OXAppUpdateHandler {
private void addNotification(Context context, int iconID,
CharSequence tickerText, CharSequence title, CharSequence content) {
CharSequence notificationTicket = tickerText;
CharSequence notificationTitle = title;
CharSequence notificationContent = content;
long when = System.currentTimeMillis();
Intent intent = new Intent(context, MainActivity_.class);
intent.setFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(OPEN_UPDATE_ACTIVITY_KEY, 1);
PendingIntent pendingIntent =
PendingIntent.getActivity(context, 0, intent, 0);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE);
Notification notification =
new Notification(iconID, notificationTicket, when);
notification.setLatestEventInfo(context, notificationTitle,
notificationContent, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
}
public static boolean isUpdateStart(Intent intent) {
Bundle bundle = intent.getExtras();
boolean result = bundle != null &&
bundle.containsKey(OPEN_UPDATE_ACTIVITY_KEY);
if (result) {
bundle.remove(OPEN_UPDATE_ACTIVITY_KEY);
}
return result;
}
}
@EActivity(R.layout.activity_main)
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (OXAppUpdateHandler.isUpdateStart(getIntent())) {
startActivity(new Intent(this, UpdateActivity_.class));
}
}
}
क्या आप कोड पोस्ट कर सकते हैं जो अतिरिक्त इरादे रखता है? –
बेस कॉन्टेक्स्ट प्राप्त करने का प्रयास करें, मुझे अधिसूचना प्रसारण या कुछ और कहां मिल रहा है। –
@ChangdeoJadhav विधि OXAppUpdateHandler। कोड intent.putExtra (OPEN_UPDATE_ACTIVITY_KEY, 1) के माध्यम से addNotification (...); – adrianosepe