- Definition: Intent (android.content.Intent) is an asynchronous message mechanism used by the Android operating system to match task requests with the appropriate Activity or Service (launching it, if necessary) and to dispatch broadcast Intents events to the system at large.
- Package: android.content.Intent.
- Android app have multiple entry points, No main function.
- One activity is designated as main / launcher activity in manifest file
- To transition from one activity to other after creating instance call startActivity() method which has “Intent” instance as argument.
- Activity can be launched in many ways using Intent
- Launching new activity by class name (Creating simple intent)
- Create instance of Intent with argument as target activity as
2. Creating Intent with Action & Data
- Intent object are composed of two main parts:
- Most common action types : ACTION_MAIN, ACTION_EDIT
- Here, intent is saying “Do this” (action) “to that” (data).
- Appropriate permission required to access activity of other package.
- Create instance of Intent with two information : action & data
- E.g. Intent dial = new Intent(Intent.ACTION_DIAL, number);
- Use Extras property
- It stores info. In Bundle object
- Create instance of Intent, use putExtra() method to put some data in form “name/value” pair as two arguments to it.
Receiving & Broadcasting Intent
- Broadcast Intent
- boradcastIntent() method is used.
- Purpose: To inform other applications about something interesting, use special intent action types.
- Special intent action e.g. ACTION_BATTERY_LOW, ACTION_BATTERY_CHANGED. (sdcard state changed, application install/uninstall).
- Receiving Broadcasted Intent
- Receive the broadcast using BroadcastReceiver
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.