私はクラス Main_Thread を持っています:
public class Main_Thread extends Thread {
...
}
次のように、 Android サービスを Main_Thread に開始するにはどうすればよいですか。
startService(new Intent(this, Main_Service.class));
私はクラス Main_Thread を持っています:
public class Main_Thread extends Thread {
...
}
次のように、 Android サービスを Main_Thread に開始するにはどうすればよいですか。
startService(new Intent(this, Main_Service.class));
このコードで:
startService(new Intent(this, Main_Service.class));
this
ApplicationContextへの参照を持つコンテキストであるアクティビティへの参照です。
その行を機能させるには、スレッドへの ApplicationContext 参照を与えて呼び出す必要があります。
startService(new Intent(context, Main_Service.class));
コンテキスト参照がある場合:
startService(new Intent(context, Main_Service.class));
そうでなければ、Activity と同じクラスでスレッドを宣言する場合:
startService(new Intent(YourActivity.this, Main_Service.class));
それ以外の場合、それが実際のアクティビティであることがわかっている場合は、次のことができます。
startService(new Intent(ActualActivity.class, Main_Service.class));