vendredi 22 mai 2015

android layout not displayed

I have trouble displaying the layout of my main activity :

I create an ActivityA with an ImageView.

In onCreate(), I launch an AsyncTask, which retrieves content from Internet, and opens an ActivityB.

When I launch my application, it displays ActivityB right away.

public class ActivityA extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MyTask mytask = new MyTask();
        mytask.execute();

    }

}

My MainActivity xml file is the following :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    android:id="@+id/loadingPanel"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/home_page"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/ic_home_page" />

    <ProgressBar
        android:id="@+id/marker_progress"
        style="?android:attr/progressBarStyle"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="center_vertical|center_horizontal"
        android:indeterminate="true" />

</RelativeLayout>

The ProgressBar is used to show the loading process of the AsyncTask.

Here is the manifest file :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
    package="com.mypackage"
    android:versionCode="19"
    android:versionName="2.2.0" >

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            android:name=".ActivityA"
            android:label="@string/title_activity_a" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ActivityB"
            android:label="@string/title_activity_b" >
        </activity>
    </application>

Here is My AsyncTask code :

public class StartSaleTrxApi extends AsyncTask<Void, String, SoapObject> {
public MyAsyncTask(Activity activity, Context context) {
        super(METHOD_NAME);
        mActivity = activity;
        mContext = context;
    }

    @Override
    protected void onPreExecute() {
       // code for onPreExecute()

    }

    @Override
    protected void doInBackground() {
      //code for doInBackground()
    }

    @Override
    protected synchronized void onPostExecute(SoapObject soapResp) {
        int code = parseReponse(soapResp);
        handleResponse(code);

    }

    private StatusCode parseReponse(SoapObject soapResp) {

        // get response status


    }

    private void handleResponse(int code) {

        switch (code) {
        case B:
            Intent b = new Intent(mContext, ActivityB.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
            mContext.startActivity(b);
            break;
        case C:
                Intent c = new Intent(mContext, ActivityB.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
                mContext.startActivity(c);

    }

thanks for helping

Aucun commentaire:

Enregistrer un commentaire