2016-12-14 36 views
0

我有兩個應用程序通過接收器相互通話。當在應用程序A中按下按鈕時,我用一定的權限廣播一個意圖。然後應用程序B喚醒進行一些計算,並再次廣播具有對應用程序A的特定權限的意圖。在這兩個清單中,我定義了許可(同名),並且還註冊了兩個接收方。接收器的生命週期

<permission android:name="aa.bb.cc.dd" 
    android:label="permission" 
    android:protectionLevel="normal"></permission> 

    <receiver android:name=".receiver" 
     android:exported="true"> 

     <uses-permission android:name="aa.bb.cc.dd"/> 

     <intent-filter> 
      <action android:name= "a_certain_action"/>/> 
     </intent-filter> 
    </receiver> 

,並呼籲他們:

Intent i = new Intent(); 
    i.setAction("a_certain_action"); 
    sendBroadcast(i,"aa.bb.cc.dd"); 

但是這同時昨天完美的工作今天在應用程序B接收器不會醒來,當我播放的意圖。這是爲什麼?

回答

1

您的應用程序可能已被殺害,並且接收方未註冊。嘗試使用服務,並在那裏註冊廣播

+0

對於接收器工作應用程序應該運行? – Libathos

+0

是的,「應用程序」必須運行。但不是整個活動,只是在你的情況下服務 –

+0

當我在我的清單中註冊一個接收者並不總是在聽一個事件? – Libathos