This seems like it should be simple, but I'm getting into a muddle.
I start an IntentService
from my main activity via an onClick
event, and listen for a response from the service using a PendingIntent
that references a static inner class BroadcastReceiver
in the same main activity of the onClick
event, i.e.,
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 ....
}
Now, all I want to do is show a ProgressBar
(swirly indeterminate one) on the activity's UI whilst the IntentService
is doing its stuff. I defined the ProgressBar
in the xml as
<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"/>
I can start it from the onClick
event by
ProgressBar pb = (ProgressBar) findViewById(R.id.progress);
pb.setVisibity(View.VISIBLE);
그러나 나는 그것을 어디에 어떻게 숨기는 지에 대해 잃어버린다 ??? myReceiver
정적 클래스 이므로 할 수 없으며 UI에 액세스 할 수 없습니다. 너무 간단 해 보이지만 최선의 방법을 찾을 수 없습니다. 어떤 제안?
감사!
두 가지 해결책을 알아낼 수 있습니다.
1. 진행률 표시 줄을 정적 참조에 할당하고 onReceive에서 보이지 않도록 설정합니다.
2. 수신기를 비 정적 상태로 만드십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다