You are on page 1of 5

EX NO:6 MULTI THREADING

/***************AndroidManifest.xml***************/
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sample2.thread"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">


<activity android:name=".Sample2threadActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".sec"></activity>
<activity android:name=".third"></activity>

</application>
</manifest>
/***************main.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"
android:background="@drawable/bluehills"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"

/>
</LinearLayout>

/***************main1.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"
android:background="@drawable/sunset"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"

/>
</LinearLayout>

/***************main2.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"
android:background="@drawable/winter"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"

/>
</LinearLayout>

/*************** Sample2threadActivity.java***************/

package sample2.thread;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class Sample2threadActivity extends Activity {


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

@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(1000);
Intent in =new
Intent(Sample2threadActivity.this,sec.class);
startActivity(in);
} catch (Exception e) {
// TODO: handle exception
}

}
}).start();
}
}
/*************** sec.java***************/
package sample2.thread;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class sec extends Activity {


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
new Thread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(1000);
Intent in =new Intent(sec.this,third.class);
startActivity(in);
} catch (Exception e) {
// TODO: handle exception
}

}
}).start();
}
}

/*************** third.java***************/
package sample2.thread;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class third extends Activity {


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
new Thread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(5000);
/*Intent in =new Intent(third.this,third.class);
startActivity(in);*/
} catch (Exception e) {
// TODO: handle exception
}

}
}).start();
}
}

OUTPUT

You might also like