Thread That I Like One

package com.app.uithread;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends Activity
{
Handler hand = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hand.postDelayed(run, 1000);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
Runnable run = new Runnable() {
@Override
public void run() {
//Thread.sleep(2000);
updateTime();
Message msg = new Message();
Bundle b = new Bundle();
b.putInt(“KEY”, 123);
msg.setData(b);
handlerTwo.sendMessage(msg);

}
};

Handler handlerTwo = new Handler(){
@Override
public void handleMessage(Message msg)
{
//String aResponse = msg.getData().getString(“message”);
Bundle b = msg.getData();
Integer value = b.getInt(“KEY”);
Toast.makeText(getApplicationContext(), “Start ” + value, Toast.LENGTH_LONG).show();
}
};

public void updateTime() {
//timer.setText(“” + (Integer.parseInt(timer.getText().toString()) – 1));
/*if (Integer.parseInt(timer.getText().toString()) == 0) {
clickme.setVisibility(0);
} else {
hand.postDelayed(run, 1000);
}*/
Message msg = new Message();
Bundle b = new Bundle();
b.putInt(“KEY”, 321);
msg.setData(b);
handlerTwo.sendMessage(msg);
Toast.makeText(getApplicationContext(), “Start”, Toast.LENGTH_LONG).show();
hand.postDelayed(run, 1000);
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s