Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8248635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:15:19+00:00 2026-06-07T23:15:19+00:00

I am having one MapActivity in which first of all I am trying to

  • 0

I am having one MapActivity in which first of all I am trying to fetch the current location of the user. For getting the current location I used the AsyncTask concept. Now What I am trying to achieve is to show the ProgressDialog to the user until got the current location.

Here is the Layout code :-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:orientation="vertical" >

    <com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:apiKey="0nO35c3MpXJisxsknk_w_fqVQa78sPhMQK3Yf5w"
        android:clickable="true" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <SeekBar
            android:id="@+id/zoombar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:max="20"
            android:progress="0" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="70dip"
        android:layout_marginTop="5dip"
        android:background="@drawable/round"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dip" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/sun" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|center_horizontal"
                android:layout_marginLeft="15dip" >

                <ImageView
                    android:id="@+id/rupee"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/rupee" />

                <TextView
                    android:id="@+id/day_amount"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical|right"
                    android:layout_marginLeft="10dip"
                    android:numeric="decimal"
                    android:text="0.0"
                    android:textColor="@color/autoText"
                    android:textSize="@dimen/text_size_medium"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>

        <View
            android:layout_width="2dip"
            android:layout_height="wrap_content"
            android:background="#ff6600" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="5dip" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/moon" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|center_horizontal"
                android:layout_marginLeft="15dip" >

                <ImageView
                    android:id="@+id/rupee"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/rupee" />

                <TextView
                    android:id="@+id/night_amount"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical|right"
                    android:layout_marginLeft="10dip"
                    android:numeric="decimal"
                    android:text="0.0"
                    android:textColor="@color/autoText"
                    android:textSize="@dimen/text_size_medium"
                    android:textStyle="bold" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

MapActivity Code :-

// Background AsyncTask Class

    class CurrentPositionTask extends AsyncTask<String, Void, Void> {
        boolean flag = true;
        @Override
        public void onPreExecute() {
            // TODO Auto-generated method stub
            System.out.println("Executed");

                    // TODO Auto-generated method stub
                    dialog = new ProgressDialog(AutoMapActivity.this.getApplicationContext());
                    dialog.setTitle("");
                    dialog.setMessage("Searching");
                    dialog.show();
        }

        @Override
        public Void doInBackground(String... params) {
            // TODO Auto-generated method stub
            while(flag){
                //System.out.println("While Loop");
                if (latitude != 0 && longitude != 0) {
                    flag = false;
                    break;
                }
            }

            return null;
        }

        @Override
        public void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            locationManager.removeUpdates(locationListener);
            if (latitude!=0 && longitude!=0) {
                dialog.cancel();
                setInit();
            }
        }
    }

    //LocationListner Class
    class MyLocationListener implements LocationListener {

        public void onLocationChanged(Location location) {
            // TODO Auto-generated method stub
            if (location != null) {
                latitude = location.getLatitude();
                longitude = location.getLongitude();
            }
        }

        public void onProviderDisabled(String arg0) {
            // TODO Auto-generated method stub
            Toast.makeText(getApplicationContext(), "Gps Disabled",
                    Toast.LENGTH_LONG).show();

        }

        public void onProviderEnabled(String arg0) {
            // TODO Auto-generated method stub
            Toast.makeText(getApplicationContext(), "Gps Enabled",
                    Toast.LENGTH_SHORT).show();
        }

        public void onStatusChanged(String provider, int status, Bundle extra) {
            // TODO Auto-generated method stub
            switch (status) {
            case 0:
                // OutofService
                Toast.makeText(getApplicationContext(), "Out of Service",
                        Toast.LENGTH_LONG).show();
                break;
            case 1:
                // Temporarily unavailable
                Toast.makeText(getApplicationContext(),
                        "Location Temporary Unavailable", Toast.LENGTH_LONG)
                        .show();
                break;
            case 2:
                // Available
                Toast.makeText(getApplicationContext(), "Available",
                        Toast.LENGTH_LONG).show();
                break;
            }
        }
    }

LOG CAT :-‘

07-17 19:37:49.267: W/System.err(881): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
07-17 19:37:49.277: W/System.err(881):  at android.view.ViewRoot.setView(ViewRoot.java:531)
07-17 19:37:49.277: W/System.err(881):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
07-17 19:37:49.277: W/System.err(881):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
07-17 19:37:49.277: W/System.err(881):  at android.app.Dialog.show(Dialog.java:241)
07-17 19:37:49.277: W/System.err(881):  at com.test.fare.AutoMapActivity$CurrentPositionTask.onPreExecute(AutoMapActivity.java:195)
07-17 19:37:49.277: W/System.err(881):  at android.os.AsyncTask.execute(AsyncTask.java:391)
07-17 19:37:49.277: W/System.err(881):  at com.test.fare.AutoMapActivity.getUserCurrentLocation(AutoMapActivity.java:146)
07-17 19:37:49.277: W/System.err(881):  at com.test.fare.AutoMapActivity.onCreate(AutoMapActivity.java:80)
07-17 19:37:49.277: W/System.err(881):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-17 19:37:49.287: W/System.err(881):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-17 19:37:49.287: W/System.err(881):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-17 19:37:49.287: W/System.err(881):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-17 19:37:49.287: W/System.err(881):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-17 19:37:49.287: W/System.err(881):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 19:37:49.287: W/System.err(881):  at android.os.Looper.loop(Looper.java:130)
07-17 19:37:49.287: W/System.err(881):  at android.app.ActivityThread.main(ActivityThread.java:3683)
07-17 19:37:49.297: W/System.err(881):  at java.lang.reflect.Method.invokeNative(Native Method)
07-17 19:37:49.297: W/System.err(881):  at java.lang.reflect.Method.invoke(Method.java:507)
07-17 19:37:49.297: W/System.err(881):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-17 19:37:49.297: W/System.err(881):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-17 19:37:49.297: W/System.err(881):  at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:15:22+00:00Added an answer on June 7, 2026 at 11:15 pm

    In MapActivity try using AutoMapActivity.this instead of AutoMapActivity.this.getApplicationContext() when creating the dialog?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having one small application which is used by some schools. I am
I am having one heck of a hard time trying to figure this out.
I am having one Gtk+ and C application in which i want to set
I'm having one hell of a time trying to get my databinding to work
Hello guys i'm having one hell of a time trying to parse an xml
I am having one heck of a time with hoverIntent. I keep getting Error:
I'm having one heck of a time getting this validation to work. I'm using
I'm having one of those bizarre this used to work and then it stopped
I am having one web service in which i have list of countries, state
Iam having one SP for which the input is a XML document . I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.