---
# System prepended metadata

title: Part A Questions With Solutions

---

# Part A Questions With Solutions
**2.Create an Android Application to demonstrate change of background color using Radio 
Buttons.**

```package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioGroup;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
RadioGroup b;
LinearLayout l;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b=findViewById(R.id.r);
        l=findViewById(R.id.main);
        b.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId==R.id.blue){
                   l.setBackgroundColor(Color.BLUE);
                } else if (checkedId==R.id.red) {
                    l.setBackgroundColor(Color.RED);

                }else{
                    l.setBackgroundColor(Color.GREEN);
                }
            }
        });
    }


}


```
#
**3.Create an Android Application to demonstrate choosing of food items and cost 
computation using Check Box.**


```package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.Toast;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
Button t;
CheckBox b,p,s;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        t=findViewById(R.id.btn);
        b=findViewById(R.id.b);
        p = findViewById(R.id.p);
        s=findViewById(R.id.s);

      t.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String li="";
              int amt=0;
              if(b.isChecked()){
                  li=li+b.getText().toString()+"\n";
                  amt+=100;
              }
              if (p.isChecked()) {
                  li=li+p.getText().toString()+"\n";
                  amt+=100;
              }
              if (s.isChecked()){
                  li=li+s.getText().toString()+"\n";
                  amt+=100;
              }
              Toast.makeText(MainActivity.this ,li+amt,Toast.LENGTH_LONG).show();
          }
      });

    }


}
```
#
**4.Create an Android Application to add and delete items from ListView dynamically.**

- An ArrayAdapter in Android is a type of adapter used to bind data from an ArrayList (or other data sources) to a UI component such as a ListView or Spinner. It acts as a bridge between the data source and the UI, allowing the data to be displayed and managed easily.

```package com.example.myapplication;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
Button t;
ListView l;
EditText e;

ArrayList<String>arr= new ArrayList<String>();
ArrayAdapter<String>adp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        t=findViewById(R.id.b);
        e=findViewById(R.id.e);
        l = findViewById(R.id.l);
        arr.add("mango");
        arr.add("Orange");

        adp=new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1,arr);
        l.setAdapter(adp);

        t.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s=e.getText().toString();
                arr.add(s);
                adp.notifyDataSetChanged();
            }
        });
        l.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                arr.remove(position);
                adp.notifyDataSetChanged();
                return false;
            }
        });
    }


}
```
#
**5.Simple Calulater**

```package com.example.myapplication;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
Button a,m,d,s ;
TextView r;
EditText e1 ,e2;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        e1=findViewById(R.id.etNumber1);
        e2=findViewById(R.id.etNumber2);
        a = findViewById(R.id.btnAdd);
        m = findViewById(R.id.btnMultiply);
        d = findViewById(R.id.btnDivide);
        s = findViewById(R.id.btnSubtract);
        r=findViewById(R.id.tvResult);



        a.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num1= Integer.parseInt(e1.getText().toString());
                int num2 = Integer.parseInt(e2.getText().toString());
                int result = num1 + num2;
                r.setText(String.valueOf(result));
            }
        });
        
        //add all other buttons Listener



    }


}
```

```<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp"
    android:paddingTop="50dp">

    <!-- Input Fields -->
    <EditText
        android:id="@+id/etNumber1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="Enter first number"
        android:inputType="numberDecimal" />

    <EditText
        android:id="@+id/etNumber2"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="Enter second number"
        android:inputType="numberDecimal" />

    <!-- Buttons for Operations -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">

        <Button
            android:id="@+id/btnAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add" />

        <Button
            android:id="@+id/btnSubtract"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Subtract"
            android:layout_marginStart="8dp" />

        <Button
            android:id="@+id/btnMultiply"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Multiply"
            android:layout_marginStart="8dp" />

        <Button
            android:id="@+id/btnDivide"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Divide"
            android:layout_marginStart="8dp" />
    </LinearLayout>

    <!-- Result Display -->
    <TextView
        android:id="@+id/tvResult"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Result: "
        android:textSize="18sp"
        android:paddingTop="16dp"
        android:gravity="center" />
</LinearLayout>
```
#
**6.Create an Android Application to send SMS.**


==Settings->apps->permisions->sms->allow==

```<uses-feature
        android:name="android.hardware.telephony"
        android:required="false" />
    <uses-permission android:name="android.permission.SEND_SMS"/>
```

```package com.example.myapplication;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
Button s;

EditText m ,p;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        m=findViewById(R.id.msg);
        p=findViewById(R.id.phn);
        s = findViewById(R.id.send);

        s.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String ph=p.getText().toString();
                String msg=m.getText().toString();

                SmsManager smsManager =SmsManager.getDefault();
                smsManager.sendTextMessage(ph,null,msg,null,null);
                Toast.makeText(MainActivity.this,"SMS Sent",Toast.LENGTH_LONG).show();
            }
        });




    }


}
```
#

**7.Create an Android Application to read the battery percentage from cellphone and 
change background color based on level using Broadcast Receiver.**




```package com.example.myapplication;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
LinearLayout c1;
TextView t;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        c1=findViewById(R.id.main);
        t=findViewById(R.id.t);
        bat_b b = new bat_b();
        registerReceiver(b,new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    }
    class bat_b extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            int per=intent.getIntExtra("level",0);

            if (per > 60) {
                c1.setBackgroundColor(Color.GREEN);
            } else if (per >= 0 && per <= 20) {
                c1.setBackgroundColor(Color.RED);
            } else {
                c1.setBackgroundColor(Color.YELLOW);
            }

        }
    }
}
```

Q: What is BroadcastReceiver in Android?
A: It is a component that listens for system-wide or application-specific broadcast messages.

Q: What does Intent.ACTION_BATTERY_CHANGED do?
A: It is a system broadcast that provides information about the current battery state.

Q: How do you register a BroadcastReceiver in your app?
A: By using registerReceiver method with an IntentFilter for the desired action.

Q: What does getIntExtra("level", 0) in onReceive do?
A: It retrieves the battery level from the Intent.

Q: Why do we use registerReceiver instead of declaring the receiver in the manifest?
A: ACTION_BATTERY_CHANGED is a sticky broadcast and is only available when registered programmatically.

Q: What is the role of EdgeToEdge.enable(this) in this code?
A: It enables edge-to-edge display for the activity, providing a modern UI look.

Q: What is the default value provided in getIntExtra and why?
A: 0 is the default value to avoid null or incorrect data when the level key is not present.

Q: What happens if the BroadcastReceiver is not unregistered?
A: It can cause memory leaks as the system will still try to send broadcasts to the receiver.

Q: Can BroadcastReceiver run on the main thread?
A: Yes, onReceive runs on the main thread, so heavy operations should be avoided.

Q: Why use Color.GREEN, Color.RED, and Color.YELLOW?
A: To visually indicate different battery levels.

Q: What is the purpose of setContentView in onCreate?
A: It sets the layout resource for the activity.

Q: Can BroadcastReceiver be used for custom broadcasts?
A: Yes, using sendBroadcast to send custom intents.

- What is an Intent in Android?: 
Definition:
An Intent is a messaging object used in Android to request an action from another app component. It facilitates communication between components such as activities, services, and broadcast receivers.


# 

**8.Create an Android Application to change image in Image View on Button Click**


```package com.example.myapplication;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.provider.MediaStore;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
ImageView i;
Button b;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        i=findViewById(R.id.imageView);
        b=findViewById(R.id.button4);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i =new Intent(MediaStore.ACTION_IMAGE_CAPTURE_SECURE);
               startActivityForResult(i,1);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == 1){
            Bitmap t=(Bitmap)data.getExtras().get("data");
            i.setImageBitmap(t);
        }
    }
}
```



- Bitmap: Represents an image in memory that you can manipulate or display in your app.

- Intent: A messaging object used to request actions from other components (like capturing an image using the camera in this case).

- startActivityForResult(): Starts an activity (camera app here) and expects a result to be returned later.

- getExtras(): Retrieves additional data passed with the Intent, which in this case contains the captured image.

# 
**9.Create an Android Application to capture video using Camera and illustrate 
playback.**

```package com.example.myapplication;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import java.util.ArrayList;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
VideoView v;
Button b;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        v=findViewById(R.id.videoView);
        b=findViewById(R.id.button4);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i =new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
               startActivityForResult(i,1);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == 1){
            Uri u = data.getData();
            v.setVideoURI(u);
            v.start();
        }
    }
}
```

```Uri u = data.getData();```

- data.getData() is used to retrieve the Uri of the video file selected by the user. This

- Uri: A URI (Uniform Resource Identifier) is used to identify and access a resource, like a video file, on the system.

- VideoView: A UI element in Android used to display and play videos.

# 

**10.Create an Android Application to demonstrate the following Android Animations. i) 
Rotate ii) Fade**

```package com.example.myapplication;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.telephony.SmsManager;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import java.util.ArrayList;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
ImageView i ;
Button  r , f;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        i=findViewById(R.id.imageView3);
        r=findViewById(R.id.button4);
        f=findViewById(R.id.button5);
        r.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Animation a = AnimationUtils.loadAnimation(MainActivity.this,R.anim.rotate);
                i.startAnimation(a);
            }
        });
        f.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Animation a = AnimationUtils.loadAnimation(MainActivity.this,R.anim.fade);
                i.startAnimation(a);
            }
        });

    }

}
```
==rotate.xml==
```<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%"
    android:pivotY="50%" android:duration="1000"/>
</set>
```

==fade.xml==
```<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:toAlpha="0" android:fromAlpha="1"
    android:duration="1000"/>
</set>
```
#

**11.Gyroscope and accelerometer**


```package com.example.myapplication;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.telephony.SmsManager;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import java.util.ArrayList;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
TextView x,y,z ;
Sensor s;
SensorManager sm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        x=findViewById(R.id.textView);
        y=findViewById(R.id.textView1);
        z=findViewById(R.id.textView2);
        sm=(SensorManager)getSystemService(SENSOR_SERVICE) ;
        s=sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

        if(s==null){
            Toast.makeText(this,"Suported",Toast.LENGTH_LONG).show();
            finish();
        }
        sm.registerListener(new SensorEventListener() {
            @Override
            public void onSensorChanged(SensorEvent event) {
               float xval=event.values[0];
                float yval=event.values[1];
                float zval=event.values[2];
                x.setText(xval+"");
                y.setText(yval+"");
                z.setText(zval+"");

            }

            @Override
            public void onAccuracyChanged(Sensor sensor, int accuracy) {

            }
        },s,SensorManager.SENSOR_DELAY_NORMAL);

    }

}

```

```<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="16dp"
    android:paddingTop="50dp"
    android:id="@+id/main">


    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />
    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />
</LinearLayout>
```

# 

# PART-B QUESTIONS


**Sql**


```package com.example.myapplication;

public class MainActivity extends AppCompatActivity {
EditText name,usn,age ;
Button insert,select;
Dbhelper db;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        db=new Dbhelper(this);
        name=findViewById(R.id.name);
        age=findViewById(R.id.age);
        usn=findViewById(R.id.usn);
        insert=findViewById(R.id.i);
        select=findViewById(R.id.s);

        insert.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String nm =name.getText().toString();
                String us = usn.getText().toString();
                int a = Integer.parseInt(age.getText().toString()) ;
                boolean res=db.InserData(nm,us,a);
                if(res){
                    Toast.makeText(MainActivity.this,"Inserted",Toast.LENGTH_LONG).show();
                }else{
                    Toast.makeText(MainActivity.this,"Not Inserted",Toast.LENGTH_LONG).show();

                }
            }
        });
        select.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String uss = usn.getText().toString();
                Cursor c = db.SelectData(uss);
                if(c.getCount()==0){
                    Toast.makeText(MainActivity.this,"No Data",Toast.LENGTH_LONG).show();
                }else{
                    c.moveToFirst();
                    String n1=c.getString(0);
                    String n2=c.getString(1);
                    int a=c.getInt(2);
                    String data = "Name:"+n1+"\nUsn:"+n2+"\nage"+a;
                    Toast.makeText(MainActivity.this,data,Toast.LENGTH_LONG).show();
                }
            }
        });


    }

}
```
```package com.example.myapplication;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class Dbhelper extends SQLiteOpenHelper {
    public Dbhelper( Context context) {
        super(context, "User1.db",null,1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE Student(name TEXT,usn TEXT primary key,age INTEGER)");

    }
    public boolean InserData(String name ,String usn,int age){
        SQLiteDatabase db=getWritableDatabase();
        ContentValues cv =new ContentValues();
        cv.put("name",name);
        cv.put("usn",usn);
        cv.put("age",age);
        long res = db.insert("Student",null,cv);
        db.close();
        return res!=1;
    }

    public Cursor SelectData(String u){
        SQLiteDatabase db = getWritableDatabase();
        Cursor c=db.rawQuery("select * from Student where usn=?",new String[]{u});
        return c;
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS Student");
    onCreate(db);
    }
}
```


# 

**Create an Android Application to demonstrate communication between two 
activities using Explicit Intents.**


==main==

```public class MainActivity extends AppCompatActivity {
EditText m ;
Button s;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);

        m=findViewById(R.id.m);
        s=findViewById(R.id.s);


        s.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            String s = m.getText().toString();
            Intent i = new Intent(MainActivity.this ,MainActivity2.class);
            i.putExtra("Msg",s);
            startActivityForResult(i,1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode==RESULT_OK){
            String s = data.getStringExtra("Ack");
            Toast.makeText(MainActivity.this,s,Toast.LENGTH_LONG).show();        }
    }
}
```
==main2==
```package com.example.myapplication;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity {
TextView t;
Button b;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main2);
        t=findViewById(R.id.textView);
        b=findViewById(R.id.btn);
        Intent i = getIntent();
        String s = i.getStringExtra("Msg");
        t.setText(s);
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent();
                i.putExtra("Ack","Recived");
                setResult(RESULT_OK,i);
                finish();
            }
        });
    }


}
```

# 
**Create an Android Application to demonstrate implicit intents for Call, Maps and 
browser activity.**

```package com.example.myapplication;



public class MainActivity extends AppCompatActivity {
    EditText e1, e2, e3;
    Button b1, b2, b3, b4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);

        e1 = findViewById(R.id.pe);
        e2 = findViewById(R.id.me);
        e3 = findViewById(R.id.be);
        b1 = findViewById(R.id.pb);
        b2 = findViewById(R.id.mb);
        b3 = findViewById(R.id.bb);

       b1.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               String s = e1.getText().toString();
               Intent call = new Intent(Intent.ACTION_VIEW,Uri.parse("tel:"+s));
               startActivity(call);
           }
       });

       b2.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               String  m= e2.getText().toString();
               Intent map = new Intent(Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+m));
               startActivity(map);
           }
       });
       b3.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               String url =e3.getText().toString();
               url="http://"+url;
               Intent brw = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
               startActivity(brw);
           }
       });



    }

}
```

# h1
**option/contextMenu**


```public class MainActivity extends AppCompatActivity {
    EditText e1, e2 ;
    TextView t;
    Button b1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);

        e1 = findViewById(R.id.e1);
        e2 = findViewById(R.id.e2);
        t=findViewById(R.id.t);
        b1 = findViewById(R.id.b1);
        registerForContextMenu(b1);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(1,101,1,"ADD");
        menu.add(1,102,2,"SUB");
        menu.add(1,103,3,"ADD");
        menu.add(1,104,4,"ADD");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.add(1,101,1,"ADD");
        menu.add(1,102,2,"SUB");
        menu.add(1,103,3,"ADD");
        menu.add(1,104,4,"ADD");

        
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        double f = Double.parseDouble(e1.getText().toString());
        double s =Double.parseDouble(e2.getText().toString());
        switch(item.getItemId()){
            case 101:t.setText(String.valueOf(f+s));
                return true;
            case 102:t.setText(String.valueOf(f-s));
                return true;
            case 103:t.setText(String.valueOf(f*s));
                return true;
            case 104:
                if (s != 0)
                    t.setText(String.valueOf(f / s));
                else
                    Toast.makeText(MainActivity.this, "Divide by zer0",
                            Toast.LENGTH_LONG).show();
                return true;
            default:
                return super.onContextItemSelected(item);
        }
    }

    @Override
    public boolean onContextItemSelected(@NonNull MenuItem item) {
        double f = Double.parseDouble(e1.getText().toString());
        double s =Double.parseDouble(e2.getText().toString());
        switch(item.getItemId()){
            case 101:t.setText(String.valueOf(f+s));
                return true;
            case 102:t.setText(String.valueOf(f-s));
                return true;
            case 103:t.setText(String.valueOf(f*s));
                return true;
            case 104:
                if (s != 0)
                    t.setText(String.valueOf(f / s));
                else
                    Toast.makeText(MainActivity.this, "Divide by zer0",
                            Toast.LENGTH_LONG).show();
                return true;
            default:
                return super.onContextItemSelected(item);
        }

    }
}

```




