Recovery the state of the first activity launched

by Joan » Thu, 14 Jan 2010 00:55:30 GMT


Sponsored Links
 ello.

I have an application that launch a thread when a ToggleButton is
pressed, but if I press the home button, a new activity is started (I
can return to the first activity if I press the back button), but I
want to recovery the first activity launched state, which have the
reference of the initial thread.

This is my code:

org.test.test.java:

package org.test;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.ToggleButton;

public class test extends Activity {

private Thread mRefresh;
private int mCounter = 0;

private ToggleButton mStartStopButton;
private TextView mTexStat;

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

mStartStopButton = (ToggleButton) findViewById
(R.id.startstop);
mTexStat = (TextView) findViewById(R.id.textStat);

mStartStopButton.setOnClickListener(new View.OnClickListener
() {
public void onClick(View v) {
if (mStartStopButton.isChecked()) {
mRefresh = new Thread(new Runnable() {
@Override
public void run() {

while (true) {

try {
Thread.sleep(1000);// 1
second
mCounter++;
} catch (InterruptedException
e) {
Log.e("test", "Error
sleeping", e);
}
}
}
});
//Start the thread
startThread();
} else {
// Stop thread an show the counter
stopThread();

}
}
});
}

private void stopThread() {
mRefresh.stop();
mTexStat.setText("Stopped, Counter = " + mCounter);
}

private void startThread() {
mRefresh.start();
mTexStat.setText("Started");

}
}

this is the mail.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dip">

<TextView android:layout_width="wrap_content"
android:id="@+id/textStatus"
android:layout_height="wrap_content"
android:text="Status:" />

<TextView android:text=""
android:id="@+id/textStat"



Other Threads

1. little niggle ...

Got the new shiny 1.6 update on my G1 this morning but have noticed a 
little problem.  When I finished listening to my voicemail I press 7 to 
delete.  The problem I had was every time I pressed 7 the number 1 was 
selected and the voicemail was played again.  This was using the virtual 
keyboard.  Pressing 7 on the hardware keyboard worked so I have a 
workaround.

Just wondering if anyone else has had virtual keyboard troubles.  Is it 
a reset to defaults or a bug in 1.6?

Sorry if this has been covered before.


Pd

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

2. neighbor cell information yields odd results with 3G

I have an app that collects neighbor cell information (CID and RSSI).
It works fine in 2G.  When switching to 3G, the getCid() and getRssi()
throw a NumberFormatException

List<NeighboringCellInfo>  neighCell = null;
neighCell = telManager.getNeighboringCellInfo();
for (i = 0; i < numNeigh; i++) {
        try {
                NeighboringCellInfo thisCell = neighCell.get(i);
                int thisNeighCID = thisCell.getCid();
                int thisNeighRSSI = thisCell.getRssi();

        } catch (NumberFormatException e) {
                e.printStackTrace();
                NeighboringCellInfo thisCell = neighCell.get(i);
                cellIdOutput = String.format("%s", neighCell.toString
());
}

Using toString() (as above in last line of the catch) generates the
following string...

[[6c at 0], [74 at 0]]

This NeighboringCellInfo list identifies it's size as 2, which looks
right from the string output.

Does this string contain 3G cell ID such as scrambling code (in hex)?
Anyone know how to decode it?

Thanks in advance for the help.

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

3. Verizon attacks iPhone with ne w 鈥楧roid鈥?campaign

4. TabHost crash (was: hardcoded borders)

5. Android 1.6 deployement status

6. Android Music Player noy indexing mp3 files

7. ADC2 entries so far...