0

I have an activity where the device checks for the latitude and longitude. After getting latitude and longitude I pass this information to a server which gets me nearest branches. But before I call the Location manager for getting latitude and longitude I call an Layout which has expandable list to fill up with getting data from server. But whenever the LocationManager is getting a fix of the satellite, lat and long, the layout does not render as I get black screen, till I get the data back from server I get black screen even in the phone. Let me know why is this screen appearing in between.

Before Data gets loaded I get this screen

After I get back from server I get this usual screen with layout enter image description here

this is part of my java code where I am calling layout first and then gps Location Manager and then hitting to the server to get branches list

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    setContentView(R.layout.findus_layout);
    /*findUsProgressbarField = (ProgressBar)findViewById(R.id.findUsProgressBar);
    findUsProgressbarField.setVisibility(View.VISIBLE);*/

    mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

    SharedPreferences findUsSetDetailsSharedPreference = getSharedPreferences("gpsdetails",MODE_PRIVATE);
    String latitudeString = findUsSetDetailsSharedPreference.getString("latitude", "");
    String longitudeString = findUsSetDetailsSharedPreference.getString("longitude", "");

    try {

    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("latitude", latitudeString));
        postParameters.add(new BasicNameValuePair("longitude", longitudeString));


   String response = CustomHttpClient.executeHttpPost("http://192.168.56.259:8080/StrutsExample/FindUS.slt",postParameters);

xml layout

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/white"
android:fillViewport="true"
android:tileMode="repeat" >

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/header"
        android:layout_alignParentTop="true"
        android:layout_width="fill_parent" 
        android:layout_height="30dip"
        android:background="@drawable/black"
        android:tileMode="repeat">
        <ImageButton 
            android:id="@+id/buttonBackFindUs"
            android:src="@drawable/greenarrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/black"
            android:tileMode="repeat"/>
      <ImageView 
          android:src="@drawable/logo"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
         </LinearLayout>
         <TextView
            android:id="@+id/FindUsTextView"
            android:fillViewport="true"
            android:layout_marginTop="30dip"
            android:layout_height="50dip"
            android:layout_width="fill_parent"/>

         <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"
     android:layout_marginTop="80dip">


 <ExpandableListView android:id="@+id/android:list"
           android:layout_width="fill_parent" 
           android:layout_height="fill_parent"/>

 <TextView android:id="@+id/android:empty"
           android:layout_width="fill_parent" 
           android:layout_height="fill_parent"
           android:text="@string/main_no_items"/>
 </LinearLayout>

   <LinearLayout
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent" 
        android:layout_height="30dip"
        android:layout_weight="1"
        android:weightSum="5" 
        android:orientation="horizontal"
        android:background="@drawable/black"
        android:tileMode="repeat">

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        android:orientation="vertical"
        android:gravity="center" 
        android:layout_height="fill_parent">

        <ImageButton 
            android:id="@+id/footerMainBtnHome"
            android:layout_width="wrap_content" 
            android:layout_height="12dip"
            android:src="@drawable/home" 
            android:background="@drawable/black"/>
        <TextView 
            android:text="Home" 
            android:textSize="8dip"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
     <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        android:orientation="vertical"
        android:gravity="center" 
        android:layout_height="fill_parent">

        <ImageButton 
            android:id="@+id/footerMainBtnProducts"
            android:layout_width="wrap_content" 
            android:layout_height="12dip"
            android:src="@drawable/products" 
            android:background="@drawable/black"/> 
            <TextView 
            android:text="Products" 
            android:textSize="8dip"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
     <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        android:orientation="vertical"
        android:gravity="center" 
        android:layout_height="fill_parent">

        <ImageButton 
            android:id="@+id/footerMainBtnCart"
            android:layout_width="wrap_content" 
            android:layout_height="12dip"
            android:src="@drawable/cart" 
            android:background="@drawable/black"/>
        <TextView 
            android:text="Cart" 
            android:textSize="8dip"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>
     <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        android:orientation="vertical"
        android:gravity="center" 
        android:layout_height="fill_parent">

        <ImageButton 
            android:id="@+id/footerMainBtnFeedback"
            android:layout_width="wrap_content" 
            android:layout_height="12dip"
            android:src="@drawable/feedback" 
            android:background="@drawable/black"/>
        <TextView 
            android:text="Feedback" 
            android:textSize="8dip"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>
     <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        android:orientation="vertical"
        android:gravity="center" 
        android:layout_height="fill_parent">

        <ImageButton 
            android:id="@+id/footerMainBtnHelp"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:src="@drawable/help" 
            android:background="@drawable/black"/>
        <TextView 
            android:text="Help" 
            android:textSize="8dip"
            android:textColor="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>



         </LinearLayout>

Could let me know what would be the problem. Looking for your reply. thanks.

Vivek Kalkur
  • 2,200
  • 2
  • 21
  • 40
Mukunda
  • 1,593
  • 3
  • 26
  • 45

1 Answers1

1

I would suggest to make all calls to remote server in AsyncTask. What happens here is the UI is blocked until you receive back the response. This is weird user experience and furthermore you risk getting ANR if the user gets held for more than 20secs if I am not wrong?

Community
  • 1
  • 1
Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
  • I have three classes one an Activity class which has the layout and expandable List View extending ExpandableListActivity and implementing onChildClickListener, second class a Location Listener for gps and third class for AsyncTask, the second and third classses are class with in first class. After Getting getting gps AsyncTask execute does not occur at all. Any helps or pointers. thanks. – Mukunda Jan 04 '12 at 09:20
  • Without seeing any more code I can not add further help. Can I see how you call the async task at least? – Boris Strandjev Jan 04 '12 at 15:19
  • I have posted whole code in a new question http://stackoverflow.com/questions/8728184/strange-behaviour-of-async-task-code-in-android/ – Mukunda Jan 04 '12 at 17:31