Я создал динамический список Activity
, который получает его содержимое из файла PHP
(через HTTP).Проблема с динамическим содержанием активности
Так что я сделать что-то вроде этого:
public class SectionFactory {
public static Intent getAppleList(Context ctx) {
Intent intent = new Intent(ctx ,MainEntryListActivity.class);
intent.putExtra("phpFileName","getApple.php");
intent.putExtra("jsonArrayName","apples");
intent.putExtra("pageTitle","Apples");
return intent;
}
public static Intent getOrangeList(Context ctx) {
Intent intent = new Intent(ctx ,MainEntryListActivity.class);
intent.putExtra("phpFileName","getOrange.php");
intent.putExtra("jsonArrayName","oranges");
intent.putExtra("pageTitle","Oranges");
return intent;
}
}
Этот класс используется от 2-х частей приложения: MainActivity
и GCMIntentService
. Излишне говорить, что основной деятельностью приложения является MainActivity
. Он содержит 2 кнопки, один для яблок и один для апельсинов. Все здесь работает очень хорошо.
Проблема в GCMIntentService
. Это класс для обработки push-уведомлений с использованием GCM. Идея состоит в том, что я получаю ответ от JSON
от нажатия, и я решаю, отправляет ли уведомление мне список Apple или Orange на основе значения в JSON
.
Проблема в том, что она всегда перенаправляется на яблоки.
public class GcmIntentService extends IntentService {
public static final String TAG = GcmIntentService.class.getSimpleName();
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
public GcmIntentService() {
super("GcmIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
} else if (GoogleCloudMessaging. MESSAGE_TYPE_DELETED.equals(messageType)) {
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
sendNotification(extras.getString("message"));
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
private void sendNotification(String msg) {
try {
Log.i(TAG,"Message: " + msg);
JSONObject obj = new JSONObject(msg);
String message = obj.getString("content");
String category = obj.getString("category");
int icon = -1;
int notificationId = -1;
Intent intent = null;
if(category.equals("apples")) {
icon = R.drawable.apples;
intent = SectionFactory.getApples(this);
notificationId = 1;
}
else if(category.equals("oranges")) {
icon = R.drawable.oranges;
intent = SectionFactory.getOranges(this);
notificationId = 2;
}
Log.d(TAG,"Category: " + category);
Log.d(TAG,"notificationId: " + notificationId);
Log.d(TAG,"PHP filename: " + intent.getStringExtra("phpFileName"));
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(icon)
.setContentTitle("Fruits")
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setContentText(message);
mBuilder.setContentIntent(contentIntent);
Notification notif = mBuilder.build();
notif.defaults |= Notification.DEFAULT_SOUND;
notif.defaults |= Notification.DEFAULT_VIBRATE;
//notif.flags |= Notification.DEFAULT_LIGHTS;
notif.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(notificationId, notif);
}
catch(Exception e) { e.printStackTrace(); }
}
}
Я также cheched это журналы
Log.d(TAG,"Category: " + category);
Log.d(TAG,"notificationId: " + notificationId);
Log.d(TAG,"PHP filename: " + intent.getStringExtra("phpFileName"));
И они выдают апельсины информацию, но страница создана с информацией яблочного.
Почему, есть ли какой-либо кеш или что-то, что мне не хватает?
EDIT: Есть около 5 фруктов, а не только яблоки и апельсины. Но он всегда показывает информацию о яблоках.
EDIT 2: GCMIntentService
также может открыть нединамическую деятельность if(category.equals("home"))
и она отлично работает.