Displaying progress bar while intent service is running

James B

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에 액세스 할 수 없습니다. 너무 간단 해 보이지만 최선의 방법을 찾을 수 없습니다. 어떤 제안?

감사!

kvh

두 가지 해결책을 알아낼 수 있습니다.

1. 진행률 표시 줄을 정적 참조에 할당하고 onReceive에서 보이지 않도록 설정합니다.

2. 수신기를 비 정적 상태로 만드십시오.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

while progress bar is running how to disable other controls of the page in WPF

분류에서Dev

Prevent onClick while Activity is displaying Progress Dialog (Android)

분류에서Dev

Android show progress bar while image loading dynamically

분류에서Dev

Splash screen with progress bar

분류에서Dev

progress bar not working for me

분류에서Dev

Progress bar not updating on Android

분류에서Dev

Refresh progress bar

분류에서Dev

Display Upload Progress in Modal with Bootstrap Progress Bar

분류에서Dev

Put border in empty progress bar

분류에서Dev

Using an indeterminate progress bar with a listview

분류에서Dev

Progress-bar for Ruby Upload

분류에서Dev

Progress bar at every GridView element

분류에서Dev

Iframe content not displaying with Fiddler running

분류에서Dev

youtube-dl file download progress with zenity progress bar

분류에서Dev

Updating progress bar asynchronously using TPL

분류에서Dev

How can I Display a Progress Bar in mplayer?

분류에서Dev

conflict betwen dplyr and progress bar (shinyIncubator)

분류에서Dev

Android custom progress bar with .gif file

분류에서Dev

implementing progress bar in wpf window with viewmodel

분류에서Dev

Custom progress bar using YouTube API

분류에서Dev

Javascript long term progress bar like Kickstarter

분류에서Dev

How to create Vertical progress bar in Bootstrap with

분류에서Dev

NoSuchMethodError when setting a custom progress bar

분류에서Dev

Linux + how to create simple Progress Bar in bash

분류에서Dev

Is there Windows 8 copy progress bar for Nautilus?

분류에서Dev

Steam isn't displaying after running [Kubuntu]

분류에서Dev

How to monitor progress of a long running command?

분류에서Dev

dynamic broadcast receiver in a service not receiving intent

분류에서Dev

Displaying an indicator while zsh is looking for completions

Related 관련 기사

뜨겁다태그

보관