prac_6(AMP)

 Practical 6 (Implicit & Explicit Intents)

6_menuoptions.xml

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

<menu xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto">

<item

android:title="Copy"

android:id="@+id/copy"

android:icon="@drawable/copy_icon"

app:showAsAction="ifRoom"/>

<item

android:id="@+id/download"

android:icon="@drawable/download_icon"

app:showAsAction="never"

android:title="Download" />

<item

app:showAsAction="always"

android:id="@+id/settings"

android:icon="@drawable/setting_icon"

android:title="Settings" />

<item

android:id="@+id/print"

android:title="Print"

android:icon="@drawable/print_icon"

app:showAsAction="withText"/>

<item

android:id="@+id/paste"

android:title="Paste"

android:icon="@drawable/paste_icon"

app:showAsAction="ifRoom"/>

</menu>

6_MainActivity.kt

package com.example.practical6

import android.content.Intent

import android.net.Uri

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle

import android.provider.Settings

import android.view.Menu

import android.view.MenuItem

import android.widget.Toast

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {

menuInflater.inflate(R.menu.menuoption, menu)

return true

}

override fun onOptionsItemSelected(item: MenuItem): Boolean {

when (item.itemId) {

R.id.copy -> {

Toast.makeText(this, "702_Copy Selected", Toast.LENGTH_SHORT).show()

val explicitintent = Intent(this,MainActivity2 ::class.java)

startActivity(explicitintent)

}

R.id.download -> {

Toast.makeText(this, "702_Download selected",Toast.LENGTH_SHORT).show()

}

R.id.print -> {

Toast.makeText(this,"702_Print selected ", Toast.LENGTH_SHORT).show()

val url = "https://www.google.com"

val implicitIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))

startActivity(implicitIntent)

return true

}

R.id.paste -> {

Toast.makeText(this, "702_Paste selected",Toast.LENGTH_SHORT).show()

}

R.id.settings -> {

Toast.makeText(this, "702_Settings selected",Toast.LENGTH_SHORT).show()

val implicitintent = Intent(Settings.ACTION_SETTINGS)

startActivity(implicitintent)

return true

}

else -> return super.onOptionsItemSelected(item)

}

return true

}

}

Comments

Popular posts from this blog

python(BI)

(PP-7)Create a class called Numbers, which has a single class attribute called MULTIPLIER, and a constructor which takes the parameters x and y (these should all be numbers). i. Write a method called add which returns the sum of the attributes x and y. ii. Write a class method called multiply, which takes a single number parameter a and returns the product of a and MULTIPLIER. iii. Write a static method called subtract, which takes two number parameters, b and c, and returns b - c. iv. Write a method called value which returns a tuple containing the values of x and y. Make this method into a property, and write a setter and a deleter for manipulating the values of x and y.