Android广播问题 - 接收消息60秒延迟

时间:2014-01-29 22:57:42

标签: android broadcastreceiver delay

我们有一个使用以下代码广播消息的进程。该消息由BroadcastReceiver接收和处理(如下所示)。我们在一些Android平板电脑和手机上遇到了一个奇怪的问题。接收器不会在60秒内接收到广播的消息。好像有些东西会阻止消息被广播/传送60秒。我们对代码进行了三次检查,代码中没有引入任何人工延迟。还有其他人看过这个问题吗?我们将非常感谢您对此问题的任何见解。

我们正在使用Xamarin.Android 4.1.0并且已经在Samsung Note 10.1和Note 3上看到了这个问题。我们还没有在Nexus 7或Sony平板电脑上看到它。

public static void BroadcastResult(string SN, string result, string errorMessage, string commandType = "DataBatch")
{
    try
    {
         Android.Content.Intent broadcastIntent = new Android.Content.Intent("com.GoServicePro.ProcessorResults");
         broadcastIntent.PutExtra("Type", commandType);
         broadcastIntent.PutExtra("SN", SN.ToString());
         broadcastIntent.PutExtra("RESULT", result);
         broadcastIntent.PutExtra("EXCEPTION", errorMessage);

         if (Global.gCustomizerCol != null)
         {
             if (Global.gCustomizerCol.Count > 0)
             {

             }
         }

         if (Global.CurrentContext == null)
             Android.App.Application.Context.SendBroadcast(broadcastIntent);
         else
             Global.CurrentContext.SendBroadcast(broadcastIntent);

         Logging.LogToProcessorLog("Broadcasted results: <" + commandType + ":" + SN + ":" + result + ":" + errorMessage + ">");
        }
        catch (Exception ex)
        {
            Logging.LogToProcessorLog("EXCEPTION: " + ex.Message + "\n" + ex.StackTrace);
        }
    }


    [BroadcastReceiver(Enabled = true, Label = "GoServicePro Receiver")]
    [IntentFilter(new string[] { "com.GoServicePro.ProcessorResults" })]
    public class ProcessorReceiver : BroadcastReceiver
    {
        /// <summary>
        /// Handler for processing completed message brodcasted by GoServiceProProcessorService.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="intent"></param>
        public override void OnReceive(Context context, Intent intent)
        {
            string commandType = intent.GetStringExtra("Type");

            try
            {
                string sn = intent.GetStringExtra("SN");
                string result = intent.GetStringExtra("RESULT");
                string error = intent.GetStringExtra("EXCEPTION");

                switch (commandType)
                {
                    case "DataBatch":
                        if (result == "SUCCESS")
                        {
                            Global.gintGSASeqNumIn += 1;
                            Database.UpdateBootDataSeqInfo();
                            Communication.QueueAck(Global.gintGSASeqNumIn);
                            Logging.LogMsg("Batch# " + sn + " was processed successfully.");

                            if (Global.SendRefresh != null)
                                Global.SendRefresh.Invoke(true, "ACTIVE_TAB", true, "GENERAL", 0, true);
                            Logging.LogMsg("Refresh sent to Main and WO forms", 2);
                        }
                        else if (result == "ABORT_FOR_BEGIN_REFRESH")
                            Logging.LogMsg("Batch# " + sn + " was aborted by SECONDARY process because it had BEGIN_FULL_REFRESH command. It will be processed by PRIMARY process");
                        else
                        {
                            Logging.LogMsg("Batch with serial# " + sn + " was NOT saved successfully. Error was:\n" + error);
                            Logging.LogMsg("Will retry batch with serial# " + sn);
                        }
                        break;

。 。 。

0 个答案:

没有答案