[Tutorial]Using Android Intent Basic

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

[Tutorial]Using Android Intent Basic

Postby nickmoi451 » Mon Apr 08, 2013 4:12 am

1. Launching to Activities

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

Code: Select all
<activity
         android:name=".SecondActivity"
         android:label="@string/title_activity_second" >
         <intent-filter>
             <action android:name="android.intent.action.MAIN" />
     
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
     </activity>


Step 2: Create Intent to call the Activity.

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

2. Start Service

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

Code: Select all
<service android:name="MyService" >
    </service>


Step 2: Create Intent to call the Service.

Code: Select all
Intent myServiceIntent = new Intent(this, MyService.class);
    startService(myServiceIntent);


2. Send BroadcastReceiver

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

Code: Select all
<receiver android:name="MyBroadcastReceiver" >
               <intent-filter>
                   <action android:name="com.example.intenttutorial.myrecevier" />
               </intent-filter>
    </receiver>


Step 2: Create Intent to send the BroadcastReceiver.

Code: Select all
Intent broadcastIntent = new Intent(broadcastFilter);
    broadcastIntent.putExtra("9Android.net","MyBroadcastReciver is called!");
    sendBroadcast(broadcastIntent);


Download code: http://www.dl.9android.net/index.php?ac ... 1365120778
Source : http://www.9android.net/intent-basic/
nickmoi451
Freshman
Freshman
 
Posts: 6
Joined: Mon Apr 08, 2013 2:12 am

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests