Pass Data To Activity: Android Programming @DrBFraser
Pass Data To Activity: Android Programming  @DrBFraser
Uploaded February 2017 | Updated November 2026, 3 hours ago
Demo of passing data to an Activity using Intents. Shows passing primitive values, and then working with an object. Discusses it effectively being pass-by-value, whereas pass-by-reference not possible with Intents.
Previous video: Switching activities ( youtube.com/watch?v=B1oaE0Odqes )

1. Passing Primitives
---------------------
* Change makeIntent() to pass in a String and int [name, age]
- Encode using myIntent.putExtra(Key, Value)
* Change onCreate() to extract data from intent
- Extract using myIntent.getStringExtra(Key)


2. Passing Object State
-----------------------
* Pass in object by value; encode parts; onCreate() constructs new object
- Can only encode primitives into Extras, so encode object's state into extra.
(Intent can launch separate application, so cannot pass object reference outside of your memory space).
- Alternatives: Parcelable, Serializable, or Gson;

3. Pass in object by ref:
-----------------------
- 2nd activity creates a new object with identical state but distinct from 1st activity's.
- Need to have a reference to the same object, but cannot put address in an Extra
- Use Singleton, Application class
Pass Data To Activity: Android ProgrammingLinux fork() IntroductionSFU CMPT276 - Project Server App Engine Web AccessSQL Lite Database: Android ProgrammingSwitching Activities in Android Studio: Android ProgrammingInstall and Run C++ in Visual Studio Code (Linux)Python in VS Code - Very Basics!Plain Java & JUnit 5 in Android StudioLocking Activity Orientation: Android ProgrammingJUnit 4 with IntelliJ: A quick introductionGit Overview: Git & EclipseEditText and TextView: Android Programming
Brian Fraser |

Pass Data To Activity: Android Programming

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER