1

中調用,正如它在標題中所述。我試圖從守護線程上的定時器發送一個意圖,該守護線程將被另一個應用程序接收。我可以這樣做還是需要在活動中調用?sendBroadcast(Intent i)是否需要從活動

還有什麼方法可以找出什麼類需要擴展或實現,而不試圖找到某人使用它的例子。

我使用的是從班裏run()功能擴展TimerTask

// send info 
    Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_SEND); 
    intent.putExtra("MyClass", playing); 
    intent.setType("*/*"); 
    sendBroadcast(intent); 

回答

0

您可以撥打sendBroadcastMethod任何活動線程的上下文,像你這樣的一個活動設置一個計時器內調用它的代碼並且您在30秒後調用sendBroadcast,與此同時,您通過執行onBackPress完成該活動,因爲您將使用 死環境(在此情況下爲活動)來調用廣播。 否則,您可以使用任何上下文來調用sendBroadcast方法。

相關問題