I am trying to increment my progress bar on a broadcast recieved but the myProgressDialog.incrementProgressBy(increment); code has no effect from my point of view. I have tried placing the command in different places but I still can see no effect at all.
Here is what my code looks like.
public static final int max = 180;
public final static int increment = (1/180);
@Override
public void onCreate(Bundle savedInstanceState) {
...
i = new Intent();
i.setAction(ITEM_CREATED);
registerReceiver(myBroadcastReceiver, new IntentFilter(ITEM_CREATED));
findFeeds = new Runnable(){
@Override
public void run()
{
getFeedObjects();
}
};
beginThread();
}
public static Context getAppContext() {
return context;
}
private void beginThread()
{
switch (checkConnectionState(OffsideLiteActivity.this))
{
case 0:
thread = new Thread(null, findItems, "DoingInBackground");
thread.start();
myProgressDialog = new ProgressDialog(this);
myProgressDialog.setCancelable(true);
myProgressDialog.setMessage("Loading...");
myProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
myProgressDialog.setProgress(0);
myProgressDialog.setMax(max);
myProgressDialog.show();
break;
case 1:
connectionError();
break;
default:
}
}
private BroadcastReceiver myBroadcastReceiver =
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent)
{
myProgressDialog.incrementProgressBy(increment);
Log.d("RECEIVED", "Broadcast received");
}
};
The interesting part is that logcat registers the Broadcast received log that i placed after the myProgressDialog.incrementProgressBy(increment); code
logcat
08-03 13:56:15.109: DEBUG/RECEIVED(8666): Broadcast received
08-03 13:56:15.109: DEBUG/RECEIVED(8666): Broadcast received
08-03 13:56:15.109: DEBUG/RECEIVED(8666): Broadcast received
08-03 13:56:15.109: DEBUG/RECEIVED(8666): Broadcast received
08-03 13:56:15.109: DEBUG/RECEIVED(8666): Broadcast received
Like I said I have tried putting the myProgressDialog.incrementProgressBy(increment); command elsewhere in my code, but to no avail. Any suggestion?
The problem might be this line:
I believe that int will be truncated to 0, so you’re only ever incrementing the progress dialog by 0. You probably want increment to be 1.