startService未啓動該服務。我從應該是應用程序上下文中調用它,但是儘管從startService之前獲得了控制檯日誌消息,但是我沒有從服務中獲得任何一個。startService在應用程序上下文中調用時未啓動
public class AntoxOnFriendRequestCallback implements OnFriendRequestCallback {
private static final String TAG = "im.tox.antox.TAG";
public static final String FRIEND_KEY = "im.tox.antox.FRIEND_KEY";
public static final String FRIEND_MESSAGE = "im.tox.antox.FRIEND_MESSAGE";
private Context ctx;
public AntoxOnFriendRequestCallback(Context ctx) {
this.ctx = ctx;
}
@Override
public void execute(String publicKey, String message){
Log.d(TAG, "Friend request callback");
Intent intent = new Intent(this.ctx, ToxService.class);
intent.setAction(Constants.FRIEND_REQUEST);
intent.putExtra(FRIEND_KEY, publicKey);
intent.putExtra(FRIEND_MESSAGE, message);
this.ctx.startService(intent);
}
}
這裏是要點:https://gist.github.com/ollieh/ed93a647430645fd2ee0
AntoxFriendRequestCallback在線61中ToxService
調用getApplicationContext()我在AntoxFriendRequestCallback
看到 「好友請求回調」 在日誌中從管線15我在ToxService的第140行日誌中看不到「Constants.FRIEND_REQUEST」,或者在MainActivity的第20行中顯示「test」。
如果你想看到完整的文件,他們在這裏: https://github.com/ollieh/Antox/tree/83eb974589a4664b2098bc0561fd0060960cfe22/app/src/main/java/im/tox/antox
請確保您的清單中有服務條目。 –
忘了提及它在那裏。此外,該服務在代碼中的其他地方成功啓動。 – ollieh