putExtra

by Kevin J. Brooks » Sun, 10 May 2009 11:05:06 GMT


Sponsored Links
 I am trying to pass a simple string in to a new activity.  I feel a
little dense.  I have looked at the samples, and I just can't seem to
get it through my thick head.  What do I need in the first parameter.

        public static final String DRINK_TYPE = "type";
.
.
.
        Intent i = new Intent(this, BeerScreen.class);
        i.putExtra(DRINK_TYPE, "beer");


Then in BeerScreen.java

        String sType = extras.getString("type");
        if(sType == "beer"){

The code inside the if is not executed.  <sigh>

Kevin




--~--~---------~--~----~------------~-------~--~----~



putExtra

by Tejas » Sun, 10 May 2009 12:34:10 GMT


 Dude,
Use Java functions equals or compareTo, "==" operator won't work

Cheers,
Tej

On May 9, 11:04pm, "Kevin J. Brooks" <bear123434...@comcast.net>


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


putExtra

by Robert Slama » Sun, 10 May 2009 13:12:47 GMT


 Hi,

if you have static final String DRINK_TYPE you can use follow construct

if(className.DRINK_TYPE.equals("beer")){
}

or make new class just with constats
class IConstants
...
public static final String DRINK_TYPE = "type";
public static final String  BEER = "beer";
public static final String LAGER = "lager";
...


and next
if(IConstants.DRINK_TYPE.equals(IConstants.BEER)){
...
}



2009/5/10 Kevin J. Brooks <bear123434...@comcast.net>:

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. desire stuck di lingkaran merah

bro...tolong donk ,my desire nyangkut di lingkaran merah aja, yg
setelah boot
any solution??

-- 
"Indonesian Android Community [id-android]" 

2. trying to save to internal memory; length of content always returns 0

Heya,

I'm trying to write something to the internal memory, but whenever I
try to check if it has written the right information, it returns
length 0.

The following code is triggered by a buttonpress, which is suppose to
store the information the user has written in a textform. 'Displaybox'
is a TextView which contains the user's addition.

String FILENAME = "geonag.txt";
                                String stringtowrite = 
Displaybox.getText().toString();
                Log.i("reached", "convert" + stringtowrite);
                                FileOutputStream fos;
                                try {
                                        fos = openFileOutput(FILENAME, 
Context.MODE_WORLD_READABLE);

                                        OutputStreamWriter fred = new 
OutputStreamWriter(fos);

                                        fred.write(stringtowrite.toCharArray(), 
0,
stringtowrite.length());
                                        fos.flush();
                                        fos.close();

                Log.i("reached", "running text 1");
                                } catch (FileNotFoundException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }

                Log.i("reached", "after file creation");

                // read this

                                FileInputStream fis2;
                                try {
                                        fis2 = openFileInput(FILENAME);


                                        InputStreamReader isr = new 
InputStreamReader(fis2);

                                        Log.i("reached","length" + 
fis2.available());
                                        char[] inputBuffer = new 
char[fis2.available()];
                                        isr.read(inputBuffer);



                                String Retrievetext = new String(inputBuffer);
                                Log.i("reached", "extra"+ Retrievetext);
                                Displaybox.setText(Retrievetext);

                                fis2.close();
                                Log.i("reached", "running text 2");

                                } catch (FileNotFoundException e1) {
                                        Log.i("reached", "file not found");
                                        // TODO Auto-generated catch block
                                        e1.printStackTrace();

                                } catch (IOException e) {

                                        Log.i("reached", "ioexception");
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();

                                }

Log.i("reached","length" + fis2.available()); --- this always seems to
return length 0.
Is there any way of checking whether the file is being created at all?
That would already help a lot.

Cheers,

-- 

3. Quick Contact Tack Implementatio

4. Darkstone HD2 froyo

5. pendapat kalian mengenai x10mini

6. Another method for app testing on new devices

7. How to change target build on Android project?