私がしたいのは、ボタンをクリックするとすぐにサービスを開始することです。サービスを開始したら、すぐに別のアクティビティを意図します。 サービスを開始して、別のアクティビティに同時にリダイレクトする方法は?
は、ここでそれを達成するために私のコードです:button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//here I start the service
Intent intent = new Intent(MyActivity.this, UploadService.class);
intent.putExtra(UploadService.ID,id);
startService(intent);
//after start the service,I want to redirect to Activity2.class
Intent intent1 = new Intent(MyActivity.this,Activity2.class);
startActivity(intent1);
}
}
しかし、私はこれを行うと、サービスが開始されていない、とない代わりに、それは前のアクティビティにリダイレクトし、Activity2.class
にリダイレクトします。
私はこの問題はまだここで同じ
は、私がUploadService.classにしようとしたものですService.class
のonHandleIntent(Intent intent)
内intent
を試してみました:
@Override
protected void onHandleIntent(Intent intent) {
//other code here
Intent intent1 = new Intent(MyActivity.this,Activity2.class);
startActivity(intent1);
}
しかし、まだサービスが起動しない、との意図以前のアクティビティ(MyActivity.classが意図しているアクティビティ)
Service
を開始した直後に別のactivity
にリダイレクトするにはどうすればよいですか?
編集: 私はまだのようなマニフェストでUploadService
を宣言:
<service
android:name=".services.UploadService"
android:enabled="true">
</service>
だから私はまだここに行方不明何?
を使用して、次に実行している場合は? – Kuls
なぜなら '.this'を使うだけでは解決できないのです。間違っていると正しい方法を教えてください。 – ken
@kenあなたのマニフェストのサービスを更新してサービスを拡張するサービスクラスを確認してください。 –