package pos.app;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
public class Android extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
Button helpButton =(Button) findViewById(R.id.login_help);
helpButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(AndroidApp.this,MyHandlerActivity.class);
startActivity(intent);
}
});
}
}
package pos.app;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.Button;
public class MyHandlerActivity extends Activity {
Button button;
MyHandler myHandler;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
setTitle("My Handler Activity");
button = (Button)findViewById(R.id.login_help);
myHandler = new MyHandler();
MyThread m = new MyThread();
new Thread(m).start();
}
class MyHandler extends Handler {
public MyHandler(){
}
public MyHandler( Looper L){
super(L);
}
@Override
public void handleMessage(Message msg){
Log.v("MyHandler", "handleMessage....");
super.handleMessage(msg);
Bundle bundle = msg.getData();
String text = bundle.getString("text");
MyHandlerActivity.this.button.setText(text);
}
}
class MyThread implements Runnable {
@Override
public void run() {
try{
Thread.sleep(1000);
}catch(Exception e){
}
Message msg = new Message();
Bundle bundle = new Bundle();
bundle.putString("text", "handler text");
msg.setData(bundle);
MyHandlerActivity.this.myHandler.sendMessage(msg);
}
}
}
[code="java"][/code]