Activity inside TabActivity doesn't work properly

by Edwin » Sat, 19 Feb 2011 18:43:16 GMT


Sponsored Links
 Hi All,

I have an activity named A which has TTS and service functions. It
works well if it is a single activity, but TTS and service are not
working if I put A into a TabActivity. I am not sure which part of the
program has problem. Maybe TabActivity have some effect for the
onActivityResult in A, thus TTS function not work.

Does anybody have idea to solve it?

Thanks

-- 



Re: Activity inside TabActivity doesn't work properly

by Zsolt Vasvari » Sat, 19 Feb 2011 19:54:44 GMT


 There are quite a few things wrong with Activities inside a
TabActivity.  Avoid them at all cost, if you can.  You should be able
to refactor your code to the point where they are not needed.




-- 


Sponsored Links


Re: Re: Activity inside TabActivity doesn't work properly

by Kwok Chun Wing, Edwin » Sat, 19 Feb 2011 23:51:36 GMT


 Should I put the onActivityResult in TabActivity instead of A activity? 
I really need them in the activity but I just want to put the acitivity 
inside a tab, so that I got problem.




There are quite a few things wrong with Activities inside a TabActivity. Avoid them at all cost, if you can. You should be able to refactor your code to the point where they are not needed.
Hi All, I have an activity named A which has TTS and service functions. It works well if it is a single activity, but TTS and service are not working if I put A into a TabActivity. I am not sure which part of the program has problem. Maybe TabActivity have some effect for the onActivityResult in A, thus TTS function not work. Does anybody have idea to solve it? Thanks
--



Re: Re: Activity inside TabActivity doesn't work properly

by Justin Anderson » Sun, 20 Feb 2011 07:50:09 GMT


 I have yet to hear of an example where someone was able to successfully put
activities inside a TabActivity.  Why it is allowed I'm not sure... The most
success comes from having a single activity and having each tab be a
different View...

On Sat, Feb 19, 2011 at 8:51 AM, Kwok Chun Wing, Edwin






-- 



Re: Re: Activity inside TabActivity doesn't work properly

by Dianne Hackborn » Sun, 20 Feb 2011 11:05:03 GMT


 Contacts is implemented like this.  At least it was a while ago, I don't
know if that is still the case.

Still, yes,  embedded activities it pretty cruddy.  One of the goals of
Fragment is to provide a better solution to replace it.

(For some perspective on where embedded activities came from -- early UI
designs for Android were very tab-oriented, and we were looking at tabs as
one of the extension points for applications, allowing the tabs to host
activities from other applications.  Ultimately though the UI moved away
from that, and we thus never implemented the (complicated) support for
cross-process embedded activities and probably never will.  So embedded
activities uses the heavy-weight activity abstraction on the theory that the
activities you host could be in separate processes, when they actually
can't.  Fragments provide a better API because they drop the pretense of
these things being so separate.)










-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 



Re: Activity inside TabActivity doesn't work properly

by ggjProjects » Fri, 20 May 2011 09:34:05 GMT


 Hi Edwin,

  Try to change:

   voice = new TextToSpeech(*this*, this);

  to: 

   voice = new TextToSpeech(*this.getParent()*, this);

  Hope this helps.

-- 



Other Threads

1. Upload jpg File to a web server

Hi all,

I've already posted this message on android beginners group, to have
more reader, I try here to ;o)

I'm currently working on an application which need to upload a jpg or
png file to my webserver.

I've tried many solutions from example picked on websites tutorials.
Every time I've got an error in the HTTP response with error code = 0.

The code I've tried is below.

Do you have any suggestion or resolution please ?
Thank you for your attention.

Floopi

PHP Code on my server is fileUpload.php:
----------------------------------------

<?php

// Where the file is going to be placed
$target_path =  $_SERVER['DOCUMENT_ROOT']."/uploads";

//Add the original filename to our target path.
$file = basename($_FILES['uploadedfile']['name']);

echo "target_path= ".$target_path." ";

//pour tester que c'est bien une image
$extensions = array('.png', '.gif', '.jpg', '.jpeg', '.JPG', '.JPEG');
$extension = strrchr($_FILES['uploadedfile']['name'], '.');

//check if the file is uploaded
if(in_array($extension, $extensions)) {

  if(is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) {
    echo "Fichier= ". $_FILES['uploadedfile']['name'] ."
telechargement OK.\n";

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'],
$target_path) === TRUE) {
      echo "The file ".  basename( $_FILES['uploadedfile']['name']).
        " has been uploaded";
    } else {
      echo "There was an error uploading the file, please try again!";
      echo "error =".basename($_FILES['uploadedfile']['error']);
      echo "file=".$_FILES['uploadedfile']['tmp_name'];
    }

  } else {
    echo " Nom du fichier : '". $_FILES['uploadedfile']['name'];
  }
 } else {
  echo "mauvaise extension de fichier";
 }

?>
-----------------------------------------------------------------------------------------------------------------------------------------------------

Android code :
---------------------
First, the main class :
-------------------------------

package com.floopi.testUpload;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class testUpload extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                //validation nom / commentaires
                final Button okbutton = (Button) findViewById(R.id.upload);
                okbutton.setOnClickListener(upload_listener);
        }

        OnClickListener upload_listener = new OnClickListener() {
                public void onClick(View v) {
                        // Perform Actions on clicks : start activity AddPticoin
                        uploadFile();
                }
        };

        public void uploadFile(){
                String urlString = 
"http://www.mysite.com/script/fileUpload.php";
                String name = "2CVjaune.jpg";

                try {
                        FileInputStream fis =this.openFileInput(name);
                        HttpFileUploader htfu = new HttpFileUploader
(urlString,"noparamshere", "2CVjaune.jpg");
                        htfu.doStart(fis);
                } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
}


Next, the class HttpFileUploader :
-----------------------------------------------

package com.floopi.testUpload;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.util.Log;

public class HttpFileUploader implements Runnable{

        URL connectURL;
        String params;
        String responseString;
        String fileName;
        byte[ ] dataToServer;
        FileInputStream fileInputStream = null;

        HttpFileUploader(String urlString, String params, String fileName ){
                try{
                        connectURL = new URL(urlString);
                }catch(Exception ex){
                        Log.i("URL FORMATION","MALFORMATED URL");
                }
                this.params = params+"=";
                this.fileName = fileName;

        }


        void doStart(FileInputStream stream){
                fileInputStream = stream;
                thirdTry();
        }

        void thirdTry(){
                String existingFileName = "2CVjaune.jpg";

                String lineEnd = "\r\n";
                String twoHyphens = "--";
                String boundary = "*****";
                String Tag="3rd";
                try
                {
                        //------------------ CLIENT REQUEST

                        Log.e(Tag,"Starting to bad things");
                        // Open a HTTP connection to the URL

                        HttpURLConnection conn = (HttpURLConnection)
connectURL.openConnection();

                        // Allow Inputs
                        conn.setDoInput(true);

                        // Allow Outputs
                        conn.setDoOutput(true);

                        // Don't use a cached copy.
                        conn.setUseCaches(false);

                        // Use a post method.
                        conn.setRequestMethod("POST");

                        conn.setRequestProperty("Connection", "Keep-Alive");

                        conn.setRequestProperty("Content-Type", "multipart/form-
data;boundary="+boundary);

                        DataOutputStream dos = new DataOutputStream( 
conn.getOutputStream
() );

                        dos.writeBytes(twoHyphens + boundary + lineEnd);
                        dos.writeBytes("Content-Disposition: form-data; 
name=\"uploadedfile
\";filename=\"" + existingFileName +"\"" + lineEnd);
                        dos.writeBytes(lineEnd);

                        Log.e(Tag,"Headers are written");

                        // create a buffer of maximum size

                        int bytesAvailable = fileInputStream.available();
                        int maxBufferSize = 1024;
                        int bufferSize = Math.min(bytesAvailable, 
maxBufferSize);
                        byte[ ] buffer = new byte[bufferSize];

                        // read file and write it into form...

                        int bytesRead = fileInputStream.read(buffer, 0, 
bufferSize);

                        while (bytesRead > 0)
                        {
                                dos.write(buffer, 0, bufferSize);
                                bytesAvailable = fileInputStream.available();
                                bufferSize = Math.min(bytesAvailable, 
maxBufferSize);
                                bytesRead = fileInputStream.read(buffer, 0, 
bufferSize);
                        }

                        // send multipart form data necesssary after file 
data...

                        dos.writeBytes(lineEnd);
                        dos.writeBytes(twoHyphens + boundary + twoHyphens + 
lineEnd);

                        // close streams
                        Log.e(Tag,"File is written");
                        fileInputStream.close();
                        dos.flush();

                        InputStream is = conn.getInputStream();
                        // retrieve the response from server
                        int ch;

                        StringBuffer b =new StringBuffer();
                        while( ( ch = is.read() ) != -1 ){
                                b.append( (char)ch );
                        }
                        String s=b.toString();
                        Log.i("Response",s);
                        dos.close();


                }
                catch (MalformedURLException ex)
                {
                        Log.e(Tag, "error URL: " + ex.getMessage(), ex);
                }

                catch (IOException ioe)
                {
                        Log.e(Tag, "error IO: " + ioe.getMessage(), ioe);
                }
        }


        @Override
        public void run() {
                // TODO Auto-generated method stub

        }

}

-- 

2. NFC support

Hi all.

Looking to develop an application to read rfid's and transmit the data
over the internet.
First of all, anyone got any recommendations on how to accomplish
this? I've been looking at using libnfc.org in conjunction with an
android phone.
I was hoping to use the emulator however it appears that the emulator
doesn't support usb plug in, hence I'm assuming it won't support the
emulation of reading an rfid tag?

Thanks all,

Matt

-- 

3. Lan information

4. android newbie

5. log messages are not displayed on logcat using devices

6. Could not open Selected VM debug port (8700)

7. Problem with installing the Composite ADB interface