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. how to mute radio and route audio via bluetooth connection

Hi All,

While driving, if I receive an incoming call the car radio is
automatically muted and the incoming call is routed through to my car
radio.  All other applications require me to switch the radio mode to
"Bluetooth Audio".

I'm curious if there is a way to simulate the default incoming call
functionality.  Specifically, I'd like to be able to have my
application interrupt, mute the radio, route it's audio through, then
when complete unmute the radio (the same as an incoming call does when
your car is setup with a mute wire).   The app works as expected other
than I can't hear any output unless the car is set to "bluetooth
audio" manually.

I haven't found much on the subject in my searches around the topic.
So far I've played with variations of following and had no luck:

AudioManager audioMan = (AudioManager)
getSystemService(Context.AUDIO_SERVICE);
audioMan.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);
audioMan.setBluetoothScoOn(true);
audioMan.setMode(AudioManager.MODE_IN_CALL);
ttsEngine.speak("Hello World", TextToSpeech.QUEUE_FLUSH, null);
audioMan.setStreamSolo(AudioManager.STREAM_VOICE_CALL, false);
audioMan.setMode(AudioManager.MODE_NORMAL);
audioMan.setBluetoothScoOn(false);

I've also included the following in the manifest file:

<uses-permission
android:name="android.permission.MODIFY_AUDIO_SETTINGS"></uses-
permission>

Honestly, I'm not even sure if I'm even close to being on the right
track since all my attempts have resulted in code that doesn't break
anything but gets me no closer to the goal.

Any assistance here would be much appreciated.

thanks,
steve

-- 

2. POSDroid

Dear All,
Have there been any traction into how Android can be used in POS
environments (Point of Sale)?
I am wondring if Android has any frameworks already in place for
facilitating easy portability of Legacy POS applications from other
platforms to Android or for facilitating easy development of nw POS
applications?

Looking forward for some response.

Thanks.

-- 

3. All Audio output to streaming

4. Make sure the surfaceView or associated SurfaceHolder has a valid Surface

5. using iText with Android

6. Display bug with buttons (and others)

7. Intent to send an SMS to multiple contacts.