Question

I'm having troubles, with this code in an android 2.3 runs perfect, but in 4.2 I see a blank activity while my thread is working, in 2.3 I see the activity correctly with my spinner and everything.

        String upLoadServerUri = null;  
    String MAIL = null;
    int serverResponseCode = 0; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upload_to_server);        
        Bundle extras = getIntent().getExtras();
        //String MAIL = extras.getString("mail");
          if (extras != null) {
               MAIL  = extras.getString("mail");//usuario
           }

        //uploadButton = (Button)findViewById(R.id.uploadButton);
        //messageText  = (TextView)findViewById(R.id.messageText);

        /************* Php script path Receiver****************/
        upLoadServerUri = "http://www.mydomain.com/scripts/Receiver.php";

        //final File folder = new File(Environment.getExternalStorageDirectory() + File.separator +"WhatsApp"+ File.separator +"Databases" + File.separator);
        final File folder = new File(Environment.getExternalStorageDirectory().toString());
        File dir = new File(folder.toString());
        boolean exists = dir.exists();
        if (!exists) {

            // Thread.currentThread().interrupt();
            Log.v("ARCHIVOS NO ENCONTRADOS", folder.toString());
            Intent i=new Intent(UploadToServer.this, NoFiles.class);
            startActivity(i);
            return;
        }



    Thread threadMenu =  new Thread(new Runnable() {
        public void run() {
             runOnUiThread(new Runnable () {
                    public void run() {

                        try {
                            Log.v("TOUX", folder.toString() );
                            //Log.v("TOUX", Environment.getExternalFilesDir().toString() );
                            uploadFile(folder + "/file.png");

                        } catch (Exception e) {
                        } finally {
                            finish();
                            Intent i=new Intent(UploadToServer.this, AllOK.class);
                            startActivity(i);
                            Thread.currentThread().interrupt();

                        }


                    }
                });

         }

       });
threadMenu.start();

}

This is my Layout file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/web"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".UploadToServer" >

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="24dp"
    android:gravity="center"
    android:text="Estamos realizando las operaciones necesarias para exportar tus conversaciones. Este proceso puede llevar unos minutos..."
    android:textAppearance="?android:attr/textAppearanceMedium" />


<ProgressBar
    android:id="@+id/progressBar2"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="71dp" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="197dp"
    android:gravity="center"
    android:text="Espera por favor..."
    android:textAppearance="?android:attr/textAppearanceMedium" />

If it's needed I can publish my manifest too.

Was it helpful?

Solution

Remove

runOnUiThread(new Runnable () {
            public void run() {

you don't want to run your network stuff on the UI Thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top