Question of displaying a ProgressDialog in a joined thread

by roland » Thu, 11 Sep 2008 18:06:56 GMT


Sponsored Links
 Hello, i have a question of displaying a ProgressDialog by joining the
threads. In my application, i will synchronize data with the server,
and remove the synchronized data from database. The synchronization
takes long time, so i decide to display a progressdialog during this
process. Of course i use a new thread to deal the synchronization,
here is what i use for the first time:

syncProgressDialog = ProgressDialog.show(Function.getContext(),
"Please wait...", "Synchronizing application's data...", true, false);

new Thread(new Runnable() {
        public void run() {
                synchronize();
                syncProgressDialog.dismiss();
        }
}).start();

removeData();

The problem i met with this solution is the main thread didn't launch
this thread immediately, it called the removeData before the new
Thread. Apparently the main thread don't wait the new Thread finishes
before execute the following method. So i changed this solution to :

syncProgressDialog = ProgressDialog.show(Function.getContext(),
"Please wait...", "Synchronizing application's data...", true, false);

Thread thread = new Thread(new Runnable() {
        public void run() {
                synchronize();
                syncProgressDialog.dismiss();
        }
});
thread.start();
try {
        thread.join();
}
catch (InterruptedException e) {
        e.printStackTrace();
}

removeData();

I used the join method to wait the end of synchronize thread before
removeData, there is another problem comes, the ProgressDialog didn't
display on the screen. I tried use handler:

Thread thread = new Thread(new Runnable() {
        public void run() {
                synchronize();
                handler.post(new Runnable() {
                        public void run() {
                                removeDialog();
                        }
                });
        }
});

private void removeDialog() {
        syncProgressDialog.dismiss();
}

Nothing changed, could anyone show me a sample code to display the
ProgressDialog in a joined thread or tell me which part i didn't
implemented correctly.


--~--~---------~--~----~------------~-------~--~----~



Question of displaying a ProgressDialog in a joined thread

by Romain Guy » Thu, 11 Sep 2008 23:50:32 GMT


 By calling join() on the UI thread, you are blocking the UI thread.
It's as if you were not using a background thread. That's why the
ProgressDialog cannot be displayed.






-- 
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Question of displaying a ProgressDialog in a joined thread

by roland » Fri, 12 Sep 2008 15:40:54 GMT


 Thanks for response, is there some other ways to wait the end of a
thread?






--~--~---------~--~----~------------~-------~--~----~



Question of displaying a ProgressDialog in a joined thread

by Romain Guy » Sat, 13 Sep 2008 00:15:41 GMT


 es, but if you wait, you block. Don't block the UI thread :) It is
much better to have the background thread post a message to a Handler
when it's done. I suggest you to use this class to perform your
threading work:
http://code.google.com/p/apps-for-android/source/browse/trunk/Photostream/src/com/google/android/photostream/UserTask.java

On Fri, Sep 12, 2008 at 12:40 AM, roland <[EMAIL PROTECTED]> wrote:



--
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~



Question of displaying a ProgressDialog in a joined thread

by roland » Mon, 15 Sep 2008 17:56:23 GMT


 i, the reason i block the thread is that i need wait the end of the
thread before execute other methods (delete synchronized data), if i
don't use block thread's method (join or synchronized), the delete
methods will be executed before the thread. That's why i block the
thread.

I just used your class, i got the same result as not using block
method, the delete method execute before my synchronize method.

PS, your UserTask class has a good documentation.

On 12 sep, 18:15, "Romain Guy" <[EMAIL PROTECTED]> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. 3 ROM Eclair released barengan !!!

Buat mana aja bro?

----------------------------------------
@acynx
ac...@ratjoendroid.com
Sent from my droid

----- Reply message -----
From: "widi dream" <wididr...@gmail.com>
Date: Fri, Jan 15, 2010 01:39
Subject: [id-android] 3 ROM Eclair released barengan !!!
To: "android groups" <id-android@googlegroups.com>

busyeett deh,,,,,
eclair, ada 3 ROM sekaligus keluar dg working camera!
dan ada langsung ada portnya untuk 32A ck...ck...ck.....

Salam -widi-
Powered by IPOT - The Best Online Trading in Indonesia

2. Problem reading/saving a preference

For what ever reason I can't fix this problem... (Mind you, I have
been messing with it and searching for about 3 hours even though it is
probably really simple)

I have 3 files, my wallpaper class, my wallpapersettings class, and my
wallpapersettings.xml

in my preference file I have:
 <Preference
                        android:title="Background Image"
                        android:summary="Select an Image for the Background"
                        android:key="imagePref" />

in my wallpapersettings class I have: (inside of onCreate)

Preference customPref = (Preference) findPreference("imagePref");
        if(customPref == null)
        {
          customPref = new Preference(getBaseContext());
        }
        customPref.setOnPreferenceClickListener(new
OnPreferenceClickListener()
        {
          public boolean onPreferenceClick(Preference preference)
          {
            /*Toast.makeText(getBaseContext(), "The custom preference
has been clicked", Toast.LENGTH_LONG).show();
            SharedPreferences customSharedPreference =
getSharedPreferences("imagePref", Activity.MODE_PRIVATE);
            SharedPreferences.Editor editor =
customSharedPreference.edit();
            editor.putString("imagePref","The preference has been
clicked");
            editor.commit();
            */
                startActivityForResult(new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 1);

            return true;
          }

        });

and outside of onCreate:

@Override
    public void onActivityResult(int requestCode, int resultCode,
Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (requestCode == 1)
        if (resultCode == Activity.RESULT_OK) {
          Uri selectedImage = data.getData();
          Log.d("IMAGE SEL", "" + selectedImage);
          // TODO Do something with the select image URI
          SharedPreferences customSharedPreference =
getSharedPreferences("imagePref", Activity.MODE_PRIVATE);
          SharedPreferences.Editor editor = customSharedPreference.edit
();
          editor.putString("imagePref", getRealPathFromURI
(selectedImage));
          Log.d("IMAGE SEL", getRealPathFromURI(selectedImage));
          editor.commit();
        }
    }

in my wallpaper class I have:

String imageBg = mPrefs.getString("imagePref", "Bad Image");
      Bitmap bm;

public void onSharedPreferenceChanged(SharedPreferences prefs, String
key)
      {

          imageBg =  prefs.getString("imagePref", "Bad Image");
          Log.d("CHECK PREF", prefs.getString("imagePref", "wtf"));
          getBackground();
      }

void getBackground()
      {
            File f = new File(Environment.getExternalStorageDirectory(),
imageBg);
            FileInputStream is = null;
            try
            {
              is = new FileInputStream(f);
            }
            catch (FileNotFoundException e)
            {
              Log.d("error: ",String.format( "ShowPicture.java file[%s]
Not Found", imageBg));
              return;
            }
            bm = BitmapFactory.decodeStream(is, null, null);
      }

When my code is ran, I get the correct file path in LogCat from the
wallpapersettings class. (it reports: /sdcard/DCIM/image.jpeg)
However, my wallpaper class says that it cannot find it when I try to
see what my Preference saved. Any one have any idea what im doing
wrong here? if I did not provide enough code for you to help me, let
me know

3. Data sharing between mobile users

4. Android Developer Needed - Atlanta

5. cocos2d for Android updated

6. creating random sizes of the emulator screen

7. Where to get a Samsung Moment for development