第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何更新數(shù)據(jù)庫?

如何更新數(shù)據(jù)庫?

C#
繁星點點滴滴 2021-05-18 01:17:36
我有一個接受推送通知的應用程序。我必須將推送通知寫入數(shù)據(jù)庫。問題在于,在數(shù)據(jù)庫中,它僅寫入最后一條消息(在我重新進入應用程序之后),并且何時將應用程序置于后臺,何時將其置于前臺。當有新數(shù)據(jù)到達時,如何做才能使數(shù)據(jù)庫保持最新狀態(tài)?我接受推送,然后將其數(shù)據(jù)寫入變量      [Service]   [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]    public class MyFirebaseMessagingService : FirebaseMessagingService    {        const string TAG = "MyFirebaseMsgService";        public override void HandleIntent(Intent intent)        {            try            {                if (intent.Extras != null)                {                    var builder = new RemoteMessage.Builder("MyFirebaseMessagingService");                    foreach (string key in intent.Extras.KeySet())                    {                        builder.AddData(key, intent.Extras.Get(key).ToString());                    }                    this.OnMessageReceived(builder.Build());                }                else                {                    base.HandleIntent(intent);                }            }            catch (Exception)            {                base.HandleIntent(intent);            }        }        public override void OnMessageReceived(RemoteMessage message)        {            Log.Debug(TAG, "From: " + message.From);            Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);            SendNotification(message.GetNotification().Body, message.Data, message.GetNotification().Title);           // Here I write the push - notification data into variables            X.Instance.title = message.GetNotification().Title;            X.Instance.body = message.GetNotification().Body;        }        private void OnStartCommand()        {            throw new NotImplementedException();        }        public class X        {            public static X Instance = new X();            public  string title;            public string body;        }   
查看完整描述

1 回答

?
MMMHUHU

TA貢獻1834條經驗 獲得超8個贊

從您的代碼看來,您似乎在onCreate中創(chuàng)建數(shù)據(jù)庫實例,并在相同的onCreate方法中輸入數(shù)據(jù)。我看不到您的數(shù)據(jù)庫的實現(xiàn)方式或類型,但是我建議您在OnMessageReceived處理程序的Db中輸入通知,每次收到新通知時都會調用它,而不是在onCreate中,因為由于某些設備配置(例如方向更改)而很少調用onCreate。


查看完整回答
反對 回復 2021-05-23
  • 1 回答
  • 0 關注
  • 147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號