これは単純なはずですが、私は混乱しています。
IntentService
イベントを介してメイン アクティビティからを開始し、イベントの同じメイン アクティビティ内の静的内部クラスを参照するonClick
を使用して、サービスからの応答をリッスンします。PendingIntent
BroadcastReceiver
onClick
public void onClick(View arg0) {
Intent intent = new Intent(this, MyService.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,0,MyReceiver,0);
startService(intent);
}
public static class MyReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// Do stuff here ....
}
今、私がやりたいProgressBar
のは、アクティビティの UI に (渦巻く不確定なもの) を表示することだけIntentService
です。ProgressBar
私はxmlで次のように定義しました
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.Holo.ProgressBar.Large"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/progress"
android:visibility="gone"/>
onClick
イベントから開始できます
ProgressBar pb = (ProgressBar) findViewById(R.id.progress);
pb.setVisibity(View.VISIBLE);
しかし、どこにどのように隠すか迷っています??? 静的クラスとして実行できずmyReceiver
、UI にアクセスできません。とても簡単に思えますが、最善の方法がわかりません。助言がありますか?
ありがとう!