Android Intent Basic Tutorial

  • Replies:0
Nguyen Ba Thanh
  • Forum posts: 14

Apr 8, 2013, 8:06:40 AM via Website

9android developer has release new tutorial for new beginer about Intent android.
today, i introduce you how to use android intent in this article in summary.
View full tutorial and download sample source at http://www.9android.net/intent-basic/
Using Intent
1. Launching to Activities

To start Activities, we must make two steps as follow:
Step 1: Declare Activity in Manifest.

1<activity
2 android:name=".SecondActivity"
3 android:label="@string/title_activity_second" >
4 <intent-filter>
5 <action android:name="android.intent.action.MAIN" />
6
7 <category android:name="android.intent.category.LAUNCHER" />
8 </intent-filter>
9 </activity>

Step 2: Create Intent to call the Activity.

1Intent secondActivity = new Intent(this, SecondActivity.class);
2 startActivity(secondActivity)
;

2.2. Start Service

To start Services, we must make two steps as follow:
Step 1: Declare Service in Manifest.

1<service android:name="MyService" >
2 </service>

Step 2: Create Intent to call the Service.
1Intent myServiceIntent = new Intent(this, MyService.class);
2 startService(myServiceIntent);

2.3. Send BroadcastReceiver

To start BroadcastReceiver, we must make two steps as follow:
Step 1: Declare BroadcastReceiver in Manifest.

1<receiver android:name="MyBroadcastReceiver" >
2 <intent-filter>
3 <action android:name="com.example.intenttutorial.myrecevier" />
4 </intent-filter>
5 </receiver>
Step 2: Create Intent to send the BroadcastReceiver.

1Intent broadcastIntent = new Intent(broadcastFilter);
2 broadcastIntent.putExtra("9Android.net","MyBroadcastReciver is called!");
3 sendBroadcast(broadcastIntent);

— modified on Apr 15, 2013, 7:03:29 AM

Sagar Patel

Reply