Nh trnh by phn II, intent c th dng thuc tnh ph component ch nh ch danh tn lp s thc thi Activity. thc hin iu ny, lp Intent cung cp cc hm l setComponent(ComponentName) v setClass(Context, Class) v setClassName(Context, String) setClassName(String, String).
Trong trng hp ny intent khng ch nh mt lp c th m thay vo dng cc d liu khc (action, data, type, etc.) v h thng t quyt nh xem lp no (app no) s thch hp p ng intent .
Thng tin action v category ca activity trong mt app p ng intent phi c khai bo trong Manifest ca app (AndroidManifest.xml) di dng Intent- filter (tt nhin nu chng ta mun gi mt built-in action th ta khng cn quan tm n vn ny). VD: PHP Code: <activity class=".NotesList" android:label="@strin g/title_notes_list"> <intent-filter> <action android:name="android.intent.action.GE T_CONTENT" /> <category android:name="android.intent.categor y.DEFAULT" /> <data android:mimeType="vnd.android.cursor.ite m/vnd.google.note" /> </intent-filter> </activity>
IV-Truyn nhn thng tin gia cc Activity s dng intent
-Gi s ta xy dng mt app c hai activites A v B nh hnh v trn. Khi bn phi Activity A ta s gi hm: PHP Code: startActivity(intentA,request_code)
-Bn pha Activity B ta s gi hm: PHP Code: setResult(return_code, intentB); Trong phn 1, mnh trnh by nhng kin thc c bn v Intent. Tip theo mnh s hng dn cc bn lm mt Tutorial n gin hiu r hn nhng vn nu trong l thuyt.
-Gi s bn cn vit mt app tnh cc phn t ca mt dy s c cho theo quy lut: PHP Code: a0,b0 nhp t bn phm a(n+1)=a(n)+b(n) b(n+1)=a(n)*b(n)
thc hin, chng ta xy dng hai Activities 1 v 2. Activity 1 s lm nhim v ly d liu nhp vo sau gi Activity 2 tnh ton kt qu v ly d liu tr v. Ngi dng s quyt nh tip tc tnh ton hay reset li t u. Ton b qu trnh ny c minh ha nh hnh v di y:
-u tin bn to mt New Project nh sau: PHP Code: Project Name: IntentBasic Target: bt k (vd 1.5) Package name: com.vietanddev.intent Application name: Intent Basic
-Tip theo bn to layout cho hai Activities nh hnh v di