To develop a Android Application that implements Multi threading.
Code for Activity_main.xml:
Code for MainActivity.java:
package com.example.exno7; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends AppCompatActivity < ImageView img; Button bt1,bt2; @Override protected void onCreate(Bundle savedInstanceState) < super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bt1 = (Button)findViewById(R.id.button); bt2= (Button) findViewById(R.id.button2); img = (ImageView)findViewById(R.id.imageView); bt1.setOnClickListener(new View.OnClickListener() < @Override public void onClick(View v) < new Thread(new Runnable() < @Override public void run() < img.post(new Runnable() < @Override public void run() < img.setImageResource(R.drawable.india1); >>); > >).start(); > >); bt2.setOnClickListener(new View.OnClickListener() < @Override public void onClick(View v) < new Thread(new Runnable() < @Override public void run() < img.post(new Runnable() < @Override public void run() < img.setImageResource(R.drawable.india2); >>); > >).start(); > >); > >
Note: Before Running the Application, Copy the Images given below and Paste it in “app -> res -> drawable” by pressing “right click mouse button on drawable” and selecting the “Paste” option.
TO DOWNLOAD THE IMAGES : CLICK HERE
Thus Android Application that implements Multi threading is developed and executed successfully.