我有一个在单独进程中运行的服务.该服务在onCreate()方法中生成一个新线程.该线程将消息发送回服务.
如果我手动启动应用程序一切正常 - Handler我的服务收到消息.但在我的测试handleMessage()方法中永远不会被调用.
如何修复测试以使handleMessage()方法有效?
谢谢!
服务:
public class MyService extends Service {
private ServiceHandler mHandler;
private final int MSG_HELLO_WORLD = 1;
private final String TAG = getClass().getSimpleName();
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
return null;
}
@Override
public void onCreate() {
Log.d(TAG, "MyService.onCreate");
super.onCreate();
mHandler = new ServiceHandler();
new Thread(new Runnable() {
@Override
public void run() {
Log.d(TAG, "Thread: run()");
while (true) { …Run Code Online (Sandbox Code Playgroud) java android android-service android-testing android-handler