Android Application Development Cookbook: 93 Recipes for Building Winning Apps



Download 32,34 Mb.
Pdf ko'rish
bet19/56
Sana26.02.2022
Hajmi32,34 Mb.
#470540
1   ...   15   16   17   18   19   20   21   22   ...   56
Bog'liq
Android Application Development Cookbook

6

ChAPter 1
Android FundAmentAls
solution
You can make use of the 
Intent
class to pass data to another activity. To pass primitive data types 
to another activity, you can use the 
putExtra()
method, as the following code snippet shows:
package net.learn2develop.passingdata;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View view) {
Intent i = new 
Intent("net.learn2develop.SecondActivity");
//---use putExtra() to add new key/value pairs---
i.putExtra("str1", "This is a string");
i.putExtra("age1", 25);
}
}
The preceding statements create an 
Intent
object and then attach two values to it using the
putExtra()
method: one for a string and one for an integer.
You can also pass in a 
Bundle
object using the 
Intent
object. A 
Bundle
object is like a dictionary 
object, as you can specify key/value pairs. To pass a 
Bundle
object using an 
Intent
object, create a 
Bundle
object, populate it, and then attach it to the 
Intent
object using the 
putExtras()
method, 
as the following code shows:
public void onClick(View view) {
Intent i = new 
Intent("net.learn2develop.SecondActivity");
//---use putExtra() to add new key/value pairs---
i.putExtra("str1", "This is a string");
i.putExtra("age1", 25);
//---use a Bundle object to add new key/values 

Download 32,34 Mb.

Do'stlaringiz bilan baham:
1   ...   15   16   17   18   19   20   21   22   ...   56




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish