Background Thread Running in Android

package com.raja.vedioapp;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity

{

@Override
protected void onCreate(Bundle savedInstanceState)

{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
         Progress();
}

protected void Progress()

{
final ProgressDialog progress=ProgressDialog.show(MainActivity.this, “Progress Task”, “Please Wait….”,true);

new Thread(){
public void run()
{
try
{
Message ms=new Message();
ms.what=1111;
handler.sendMessage(ms);
}catch (Exception e)
{
System.out.println(“error “+e);
}
progress.cancel();
}
}.start();

}
Handler handler=new Handler()
{

@Override
public void handleMessage(Message msg)
{
switch(msg.what)
{
case 1111:
for(int i=0;i<1000;i++)
{
System.out.println(“Back Ground Thread Test”+i);
}
break;
}
}
};

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

%d bloggers like this: