Muloqot bilan faollik yana bir bor startActivity chaqiruvlari bilan boshlanadi

Menda qiziq narsa bor. Serverda sinxronlashtiradigan android buyurtmaimga xizmat ko'rsatuvchi ilovam bor va yangi buyurtma paydo bo'lganda SHO/DISMISS tugmalari bilan bildirishnoma va dialog ko'rsatiladi. Men faoliyat olib borayotgan faoliyatimdan qat'i nazar, suhbatni namoyish qilishim kerakligi sababli, uni boshqa xizmat sifatida ishga tushirdim, yangi buyurtma paydo bo'lganda xizmatdan boshlayman.

Faoliyat hech qanday ko'rinishga ega emas, faqatgina AlertDialog yaratadi. SHOW tugmasi OrdersListActivity-ni boshlaydi va DISMISS tugmasi dialogni o'chiradi. Har bir narsa yaxshi ishlaydi, lekin faqat birinchi marta. Agar men dialogni bekor qilsam va yana bir buyurtma keladi, yana ko'rsatiladi. Shunga qaramasdan, SHOW tugmachasini bosgan holda, OrdersList ko'rsatiladi, ammo keyinchalik boshqa buyurtma kelganda, dialog ko'rsatilmaydi. Garchi, logcat bo'yicha, faoliyat boshladi. Men bunga bir necha soatcha aralashib qoldim, menga yordam bera olasizmi? Rahmat.

Mening xizmatim sinfining usuli (xabarnomani yuboradi, translyatsiya yuboradi va Dialog faoliyatini boshlaydi):

ommaviy void notifyNewOrder() {

    Context context = getApplicationContext();

    Intent notificationIntent = new Intent(this, OrdersService.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

    newOrderNotification.setLatestEventInfo(this, getString(R.string.notification_text), getString(R.string.notification_text), contentIntent);
    notificationManager.notify(NOTIFICATION_ID, newOrderNotification);


    Intent intent = new Intent(NEW_ORDER_RECEIVED);
    sendBroadcast(intent);

    Intent dialog = new Intent(context, NotificationDialog.class);
    dialog.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(dialog);

}

NotificationDialog faoliyat sinfining kodi:

Public class NotificationDialog faoliyati kengaytirmoqda {

private static final int DIALOG_NEW_ORDER = 0;
private static final String LOG_TAG = "NotificationDialog"; 

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    Log.d(LOG_TAG, "onCreate - creating activity...");

}

@Override
public void onResume() {

    super.onResume();
    Log.d(LOG_TAG, "onResume - starting the dialog...");
    showDialog(DIALOG_NEW_ORDER);

}



@Override
protected Dialog onCreateDialog(int id) {

    Dialog dialog;

    switch(id) {
        case DIALOG_NEW_ORDER:

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(R.string.notification_dialog_new_order)
                   .setCancelable(false)
                   .setPositiveButton(R.string.notification_dialog_show, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                            /*
                            * Cancel the notification
                            */
                            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                            notificationManager.cancel(OrdersService.NOTIFICATION_ID);                              

                            /*
                             * Go to the list
                             */
                            Intent listIntent = new Intent(getApplicationContext(), OrdersListActivity.class);
                            startActivity(listIntent);

                            dialog.dismiss();
                            finish();

                        }

                   })
                   .setNegativeButton(R.string.notification_dialog_dismiss, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                            /*
                             * Cancel the notification
                             */
                            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                            notificationManager.cancel(OrdersService.NOTIFICATION_ID);
                            dialog.dismiss();
                            finish();
                        }
                   });

            dialog = builder.create();

            break;        
        default:
            dialog = null;
    }

    return dialog;
}

}

NotificationDialog faoliyatining onCreate va Reesume usullarida ba'zi jurnallarni qo'shib qo'ydim va quyidagilarni aniqladim:

  1. NotificationDialog faoliyati birinchi marta boshlanganida, bu disk raskadrovka xabarlari chiqariladi
  2. Ikkinchi marta, va boshqa barcha vaqtlarda ular login qilmaydi, lekin aytganda: 10-28 10: 00: 38.074: INFO/ActivityManager (63): Boshlash: Niyat = {0x10000000 cmp = pl .mymeal.orders/.services.NotificationDialog} pid 1001 dan
0
Ajoyib, bu albatta ishlagan. Faoliyat bayroqlarini chuqurroq o'rganishim kerak deb o'ylayman. Yana bir bor rahmat.
qo'shib qo'ydi muallif Filip Majernik, manba
Bayroqni FLAG_ACTIVITY_CLEAR_TOP-ga o'zgartiring
qo'shib qo'ydi muallif Nikola Despotoski, manba
Agar bu ish bo'lsa. Fikrimni javob sifatida qo'ydim va uni qabul qilaman :)
qo'shib qo'ydi muallif Nikola Despotoski, manba

1 javoblar

Bayroqni FLAG_ACTIVITY_CLEAR_TOP ga o'zgartirish. Faqat serverdan olingan yangi ma'lumotlarda hech qanday shafqat yo'qligini eslaylik.

2
qo'shib qo'ydi