I think I have a problem in my "final Handler handler = new Handler" -
method.
My progressbar declaration is :
progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
But the handler dismis the dialog only when:
int total = msg.getData().getInt("total");
progDialog.setProgress(total);
if (total <= 0){
dismissDialog(0);
progThread.setState(ProgressbarThread.DONE);
}
But I have no "total".
So I have no condition to call dismissDialog, or?
Does someone has an idea, how i can handle this?
On 10 Apr., 15:51, Justin Anderson <[email protected]> wrote:
> Use adb and logcat to find out the cause of the problem and then fix it.
>
> Thanks,
> Justin Anderson
> MagouyaWare Developerhttp://sites.google.com/site/magouyaware
>
>
>
> On Mon, Apr 9, 2012 at 2:59 AM, Tom <[email protected]> wrote:
> > Hello,
>
> > I've implemented an example of showDialog in my SourceCode. This works
> > normally really good. But my problem is, if you press the Back-Button
> > during the Progressbar dialog is showing.
> > The App crashes. If I write a Log in the Handler method ( "final
> > Handler handler = new Handler() ") I see the the App is finished but
> > the handler method still in a loop.
> > Does someone has a tip or a example what I can do?
>
> > Cheers
>
> > Tom
>
> > import android.app.AlertDialog;
> > import android.app.Dialog;
> > import android.app.ProgressDialog;
> > import android.content.Intent;
> > import android.content.SharedPreferences;
> > import android.database.Cursor;
> > import android.graphics.Bitmap;
> > import android.graphics.BitmapFactory;
> > import android.graphics.Canvas;
> > import android.graphics.Paint;
> > import android.graphics.Paint.Style;
> > import android.graphics.Point;
> > import android.graphics.RectF;
> > import android.location.Location;
> > import android.location.LocationListener;
> > import android.net.Uri;
> > import android.os.Bundle;
> > import android.os.Handler;
> > import android.os.Message;
> > import android.preference.PreferenceManager;
> > import android.util.Log;
> > import android.view.KeyEvent;
> > import android.view.Menu;
> > import android.view.MenuItem;
> > import android.view.Window;
> > import android.widget.Toast;
>
> > import com.google.android.maps.GeoPoint;
> > import com.google.android.maps.MapActivity;
> > import com.google.android.maps.MapController;
> > import com.google.android.maps.MapView;
> > import com.google.android.maps.MyLocationOverlay;
> > import com.google.android.maps.Overlay;
>
> > import de.tektom.geoformel.common.ProgressbarThread;
>
> > /**
> > * Zeigt Google Maps in einer MapActivity an.
> > * <p>
> > * Im Emulator zum Beispiel die Koordinaten mit <br>
> > * geo fix 7.1 51 300 <br>
> > * setzen um etwas zu sehen.
> > *
> > * @author David Müller, Arno Becker, 2010 visionera gmbh
> > */
> > public class KarteAnzeigenActivity extends MapActivity implements
> > LocationListener {
> > private MapController map_Controller;
> > private MapView map_View;
> > private MyLocationOverlay mMyLocationOverlay ;
> > private GeoKontaktOverlay mMapViewOverlay;
> > private ProgressbarThread progThread;
> > private ProgressDialog progDialog;
>
> > private float mlatitude;
> > private float mlongitude;
> > /** Kuerzel fuers Logging. */
> > private static final String TAG =
> > KarteAnzeigenActivity.class.getSimpleName();
>
> > @Override
> > public void onCreate(Bundle savedInstanceState) {
> > try
> > {
> > requestWindowFeature(Window.FEATURE_LEFT_ICON);
> > super.onCreate(savedInstanceState);
> > setContentView(R.layout.mapkarte);
>
> > setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.icon);
>
> > showDialog(0);
>
> > if(getIntent().hasExtra("latitude") ==
> > true)
> > mlatitude =
> > getIntent().getExtras().getFloat("latitude");
> > if(getIntent().hasExtra("longitude") ==
> > true)
> > mlongitude =
> > getIntent().getExtras().getFloat("longitude");
>
> > initMapView();
>
> > // fuege der MapView das Overlay fuer die
> > // empfangene Position hinzu
> > initGCFormelOverlay();
>
> > // Zeige die eigene Position mit Hilfe
> > // des Overlays aus der Google Api
> > initMyLocationOverlay();
> > // create an overlay that shows our current
> > location
>
> > }
> > catch (Exception ex)
> > {
> > Log.i(TAG, ex.getMessage());
> > Toast.makeText(this,"UI problem in " + TAG + "-" +
> > ex.getMessage(),Toast.LENGTH_LONG).show();
>
> > }
> > }
>
> > public void onLocationChanged(Location location) {
> > mlatitude = (int) (location.getLatitude());
> > mlongitude = (int) (location.getLongitude());
> > }
>
> > public void onStatusChanged(String provider, int status,
> > Bundle
> > extras) {
> > // TODO Auto-generated method stub
>
> > }
>
> > public void onProviderEnabled(String provider) {
> > Toast.makeText(this, "Enabled new provider " +
> > provider,
> > Toast.LENGTH_SHORT).show();
> > }
>
> > public void onProviderDisabled(String provider) {
> > Toast.makeText(this, "Disenabled provider " +
> > provider,
> > Toast.LENGTH_SHORT).show();
> > }
>
> > @Override
> > protected boolean isLocationDisplayed() {
> > return super.isLocationDisplayed();
> > }
>
> > @Override
> > protected boolean isRouteDisplayed() {
> > return false;
> > }
>
> > @Override
> > protected void onPause() {
> > // TODO Auto-generated method stub
> > mMyLocationOverlay.disableMyLocation();
> > mMyLocationOverlay.disableCompass();
> > super.onPause();
> > }
>
> > @Override
> > protected void onResume() {
> > mMyLocationOverlay.enableMyLocation();
> > mMyLocationOverlay.enableCompass();
>
> > map_View.invalidate();
>
> > super.onResume();
> > }
>
> > @Override
> > protected void onDestroy() {
> > Log.d(TAG, "onDestroy() aufgerufen...");
>
> > super.onDestroy();
> > }
>
> > // Method to create a progress bar dialog of either spinner or
> > horizontal type
> > @Override
> > protected Dialog onCreateDialog(int id) {
> > switch(id) {
> > case 0: // Spinner
> > progDialog = new ProgressDialog(this);
>
> > progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
> > progDialog.setMessage("Loading...");
> > progDialog.setIndeterminate(true);
> > progDialog.setCancelable(true);
> > progThread = new ProgressbarThread(handler);
>
> > progThread.start();
> > return progDialog;
> > default:
> > return null;
> > }
> > }
>
> > // Handler on the main (UI) thread that will receive messages
> > from the
> > // second thread and update the progress.
>
> > final Handler handler = new Handler() {
> > public void handleMessage(Message msg) {
> > try
> > {
> > Log.w(TAG, "Handler still activ");
> > // Get the current value of the variable total from the
> > message data
> > // and update the progress bar.
> > int total = msg.getData().getInt("total");
> > progDialog.setProgress(total);
> > if (total <= 0){
> > dismissDialog(0);
> > progThread.setState(ProgressbarThread.DONE);
> > }
> > }
> > catch(Exception ex)
> > {
>
> > }
> > }
>
> > };
> > public boolean onKeyDown(int keyCode, KeyEvent event)
> > {
> > if (keyCode == KeyEvent.KEYCODE_BACK &&
> > progDialog.isShowing())
> > {
> > // DO SOMETHING
> > dismissDialog(0);
> > }
>
> > // Call super code so we dont limit default interaction
> > super.onKeyDown(keyCode, event);
>
> > return true;
> > }
> > }
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en- Zitierten Text
> >ausblenden -
>
> - Zitierten Text anzeigen -
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en