CMPE419 Mobile Application Development

Slides:



Advertisements
Similar presentations
@2011 Mihail L. Sichitiu1 Android Introduction Hello Views Part 1.
Advertisements

Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Presenting Lists of Data. Lists of Data Issues involved – unknown number of elements – allowing the user to scroll Data sources – most common ArrayList.
Android Accessing GPS Ken Nguyen Clayton State University 2012.
@2011 Mihail L. Sichitiu1 Android Introduction GUI Menu Many thanks to Jun Bum Lim for his help with this tutorial.
로봇 전화번호부 4/4 UNIT 12 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 뷰 홀더 패턴을 사용할 수 있다. 토스트를 사용할 수 있다. 클릭 이벤트를 처리할 수 있다. 2.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
Create Navigation Drawer Team 2 Zhong Wang Jiaming Dong Philip Wu Lingduo Kong.
로봇 모니터링 1/2 UNIT 20 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Message Queue Handler 2.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
New Activity On Button Click via Intent. App->res->Layout->Blank Activity A new xml file is created and a new class is added to java folder. In manifest.xml.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
Activities and Intents Richard S. Stansbury 2015.
Intents 1 CS440. Intents  Message passing mechanism  Most common uses:  starting an Activity (open an , contact, etc.)  starting an Activity.
로봇을 조종하자 4/4 UNIT 18 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Intent Activity 호출 2.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
David Sutton SMS TELEPHONY IN ANDROID. OUTLINE  This week’s exercise, an SMS Pub Quiz  Simulating telephony on an emulator  Broadcast Intents and broadcast.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Lab7 – Advanced.
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
Java Examples Embedded System Software
several communicating screens
GUI Programming Fundamentals
Android – Event Handling
ListView: Part 2.
Android Widgets 1 7 August 2018
ITEC535 – Mobile Programming
Picasso Revisted.
CIS 470 Mobile App Development
Android Programming Lecture 6
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
UNIT 08 그림책 만들기 2/2 로봇 SW 콘텐츠 교육원 조용수.
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Mobile Computing With Android ACST 4550 Android Database Storage
Activities and Intents
CIS 470 Mobile App Development
滑動 建國科技大學 資管系 饒瑞佶.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
ארועים ומאזינים android.
CMPE419 Mobile Application Development
Adding Components to Activity
CMPE419 Mobile Application Development
SE4S701 Mobile Application Development
CMPE419 Mobile Application Development
BLP 4216 MOBİL UYGULAMA GELİŞTİRME-2
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Activities, Fragments, and Intents
Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 470 Mobile App Development
Presentation transcript:

CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren 2017-2018 SPRING Computer Engineering Department CMPE419 AU

Passing data between activities in Android

Code for passing data between activities in Android : MainActivity.java String value = "Hello!"; Intent in = new Intent(this,MainActivity2.class); in.putExtra("Key", value); startActivity(in); MainActivity2.java Bundle bundle = getIntent().getExtras(); String valueReceived = bundle .getString("Key");

Code for passing multiple data or values between activities in Android : Method 1: Using Intent to pass data and Bundle to extract data between activities in Android MainActivity.java: String value1 = "Hello!"; String value2 = "Hi!"; Intent in = new Intent(this,MainActivity2.class); in.putExtra("Key1", value1); in.putExtra("Key2", value2); startActivity(in); MainActivity2.java: Bundle bundle = getIntent().getExtras(); String valueReceived1 = bundle .getString("Key1"); String valueReceived2 = bundle .getString("Key2");

Method 2 : Using Bundle to pass and to extract data between activities in Android MainActivity.java String value1 = "Hello!"; String value2 = "Hi!"; Intent in = new Intent(this,MainActivity2.class); Bundle bundle = new Bundle(); bundle.putString("Key1", value1); bundle.putString("Key2", value2); in.putExtras(bundle); startActivity(in); MainActivity2.java Bundle bundle = getIntent().getExtras(); String valueReceived1 = bundle .getString("Key1"); String valueReceived2 = bundle .getString("Key2");  

Code for passing array between activities in Android : MainActivity.java String[] array = new String[]{"Item1", "Item2", "item3", "Item4", "item5"}; Intent in = new Intent(this,MainActivity2.class); Bundle bundle = new Bundle(); bundle.putStringArray("MyArray", array); in.putExtras(bundle); startActivity(in); MainActivity2.java Bundle bundle = getIntent().getExtras(); String arrayReceived[] = bundle.getStringArray("MyArray");

Code for passing ArrayList between activities in Android : MainActivity.java ArrayList<String> array = new ArrayList<String>(); array.add("Hello"); array.add("Hi"); array.add("Bye"); Intent intent = new Intent(this, MainActivity2.class); intent.putExtra("array_list", array); startActivity(intent); MainActivity2.java Bundle bundle = getIntent().getExtras(); ArrayList<String> array = (ArrayList<String>)bundle.getStringArrayList("array_list");

Code for passing ArrayList <object> between activities in Android : MainActivity.java ArrayList<Student> stulist=new ArrayList<Student>(); //add students to your list Intent i=new Intent(MainActivity.this,NewActivity.class); Bundle bundle=new Bundle(); bundle.putSerializable("students",stulist); i.putExtras(bundle); startActivity(i);

NewActivity.java Bundle bundleobje=getIntent().getExtras(); ArrayList stulis=(ArrayList<Student>) bundleobje.getSerializable("students");

public class MainActivity extends Activity { ArrayList<Student> stulist; Button Add,Send; EditText Edtn,Edts,Edtg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); stulist=new ArrayList<Student>(); Init(); } private void Init() { Add=(Button)findViewById(R.id.button); Send=(Button)findViewById(R.id.button2); Edtn=(EditText)findViewById(R.id.editText); Edts=(EditText)findViewById(R.id.editText2); Edtg=(EditText)findViewById(R.id.editText3); Add.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String Name=Edtn.getText().toString(); Student Stu=new Student(Name,Edts.getText().toString(),Integer.parseInt(Edtg.getText().toString())); stulist.add(Stu); Edtg.setText(""); Edtn.setText(""); Edts.setText(""); }); Send.setOnClickListener(new View.OnClickListener() { Intent i=new Intent(MainActivity.this,NewActivity.class); Bundle bundle=new Bundle(); bundle.putSerializable("students",stulist); i.putExtras(bundle); startActivity(i); } }

NewActivity.Java; ArrayList<Student> stulis; ArrayAdapter adapter; ListView mylist; String[] liststring; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new); getstudents(); } private void getstudents() { Bundle bundleobje=getIntent().getExtras(); stulis=(ArrayList<Student>) bundleobje.getSerializable("students"); liststring=new String[stulis.size()]; for(int i=0;i<stulis.size();i++) liststring[i]=stulis.get(i).getName()+" "+stulis.get(i).getSurname()+" "+stulis.get(i).getGrade(); mylist=(ListView)findViewById(R.id.listView); adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,liststring); mylist.setAdapter(adapter);

import java.io.Serializable; /** * Created by PC on 09-Apr-18. */ public class Student implements Serializable { private String Name; private String Surname; private int Grade; Student(String Name, String Surname, int Grade){ this.Name=Name; this.Surname=Surname; this.Grade=Grade; } public String getName() { return Name; public int getGrade() { return Grade; public String getSurname() { return Surname; public void setGrade(int grade) { Grade = grade; public void setName(String name) { Name = name; public void setSurname(String surname) { Surname = surname;