0% found this document useful (0 votes)
55 views8 pages

Practical No - 18

The document discusses implementing implicit and explicit intents in Android. It includes XML layout files and Java code for an activity to make an implicit phone call intent and activities to pass an integer value between activities via an explicit intent.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views8 pages

Practical No - 18

The document discusses implementing implicit and explicit intents in Android. It includes XML layout files and Java code for an activity to make an implicit phone call intent and activities to pass an integer value between activities via an explicit intent.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

“Program To Implement Implicite Intent”

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">

<EditText
android:layout_width="wrap_content"
android:layout_height="50dp"
android:hint="Enter Number!"
android:layout_centerInParent="true"
android:id="@+id/et1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dial"
android:id="@+id/bt1"
android:onClick="open"
android:layout_below="@+id/et1"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
MainActivity.java

public class MainActivity extends AppCompatActivity {


Button btn;
@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=findViewById(R.id.bt1);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_DIAL);
i.setData((Uri.parse("tel:8830501213")));
startActivity(i);
}
});
}
}

“Program To Implement Explicite Intent”

activity_main.xml

<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"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:text="Activity No 1"
android:textColor="#00BCD4"
android:textSize="28sp"
android:layout_gravity="center_horizontal"
android:textStyle="bold"/>

<EditText
android:id="@+id/text1"
android:layout_width="135sp"
android:layout_height="wrap_content"
android:hint="Enter A Number"
android:layout_marginTop="48sp"
android:layout_marginLeft="140sp"/>

<Button
android:id="@+id/butt"
android:layout_width="250sp"
android:layout_height="wrap_content"
android:layout_marginLeft="90sp"
android:layout_marginTop="48sp"
android:text="Submit"
android:textSize="20sp"
android:textStyle="bold"/>

</LinearLayout>

second_activity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100sp"
android:text="Second Activity"
android:textColor="#7651B6"
android:textSize="30sp"
android:textStyle="bold"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:layout_gravity="center_horizontal"
android:text="The Factorial is :"
android:textColor="#8BC34A"
android:textSize="25sp"
android:textStyle="bold"/>

<TextView
android:id="@+id/text30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50sp"
android:textColor="#009688"
android:textSize="40sp"
android:textStyle="bold"/>
</LinearLayout>

MainActivity.java
public class MainActivity extends AppCompatActivity {
EditText edit1;
Button btn;

@Override
protected void onCreate(Bundle savedinstanceState) {
super.onCreate(savedinstanceState);
setContentView(R.layout.activity_main);

edit1 = findViewById(R.id.text1);
btn = findViewById(R.id.butt);

Bundle bundle = new Bundle();


btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View V){
int value = Integer.parseInt(edit1.getText().toString());
bundle.putInt("key",value);
Intent intent = new Intent(MainActivity.this,second_main.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
}

second_main.java
public class second_main extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity);

TextView result = findViewById(R.id.text30);


Intent intent = getIntent();
Bundle bundle = intent.getExtras();
int num = bundle.getInt("key");

int x = 1;
while (num >= 1) {
x = x * num;
num = num - 1;
String txt = Integer.toString(x);
result.setText(txt);
}
}
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ExpliciteIntent"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".second_main"> </activity>
</application>

</manifest>

You might also like