Tsarin babbar manhajar Android (6)
Broadcast Receibers Sai kalmar “Broadcast Receibers,” wacce ke aiki da wani tsari na musamman mai suna “Push-Subscribe Mechanism.” “Broadcast Receibers” tsari ne da aka gina kan babbar manhajar Android, wanda ke lura da aukuwar al’amura a waya, da kuma sanar da aukuwarsu, don baiwa wadanda ke da alhakin yin wani abu kan wannan lamari, damar […]
Broadcast Receibers
Sai kalmar “Broadcast Receibers,” wacce ke aiki da wani tsari na musamman mai suna “Push-Subscribe Mechanism.” “Broadcast Receibers” tsari ne da aka gina kan babbar manhajar Android, wanda ke lura da aukuwar al’amura a waya, da kuma sanar da aukuwarsu, don baiwa wadanda ke da alhakin yin wani abu kan wannan lamari, damar yin abin da ya kamata.” Wasu bayanai ne aka ajiye, suna kwance a cikin wayar, sai wani lamari ya faru suke farkawa, don sanar da aukuwar abin. Ba tsari ba ne mai wahala. Amma idan babu misali, zai yi wahala mai karatu ya fahimci tsarin.
Babban misali na kan manhajar sakonnin tes. Idan aka turo maka sakon tes ya shigo cikin wayarka, a ka’ida ta asali, ya kamata kawai ka ga tes din ne, babu abin da zai fadakar da kai cewa wani sako ya shigo. Amma ba haka lamarin yake ba a yanzu. Idan tes ya shigo, ko dai ka ji sautin shigowarsa ne, wanda ke fadakar da kai hakan, ko kuma ka ji diri (wato “bibrating”); ya danganci yadda ka tsara wayar. Wannan diri ko sauti da ya fadakar da kai, duk ana kiransu “Broadcast Receibers,” wato “Masu karban sakon fadakarwa don su fadakar da mai waya.” Haka idan wani ya kira layinka, a halin yanzu wayarka za ta fadakar da kai ne ta hanyar sauti (Ringing) ko ta hanyar diri (bibrating) ko ta dukkan hanyoyin biyu (bibrate then ring) ko kuma ta hanyar ganin sunan wanda ke kiranka a fuskar wayar, kai tsaye. Wannan zai faru ne idan ka hana ta kara ko diri. Ma’ana ka sanya ta a yanayin “Shiru” (Silence) kenan. Wadannan hanyoyin fadakarwa na sauti da diri, duk ana kiransu “Broadcast Receibers” ne. Wannan karin misali ne kan misalin farko.
A daya bangaren kuma, idan makamashin batirinka ya yi kasa (Low Battery), a ka’ida za ka iya gane hakan ne kawai ta hanyar ganin tambarin batir da ke fuskar wayarka yana raguwa daga sama zuwa kasa. Amma a halin yanzu a zahiri lamarin bai tsaya a haka kadai ba. Idan batir ya yi kasa a yanzu nan take za ka ji wayar tana tsowa idan waya kake yi, alamar fadakarwa ce cewa: “Ka lura, batirinka ya kusa karewa.” Haka idan batirin ya kusan zuwa karshe, ma’ana karancin ya kai makuran karanci, nan take wayar za ta shawarceka da ko dai ka sa ta a caji, ko kuma ka mayar da ita yanayin da za ta iya rayuwa cikin karancin makamashin da ta samu kanta. Idan ka ki, nan take da kanta za ta rage kaifin hasken da ke shafinta, sannan ta kashe wasu manhajojin da ke karkashin kasa wadanda ke cin makamashi, idan tafiya ta yi nisa kuma ba ka sa ta a caji ba, nan take sai ta dauke; hasken ya dusashe. Wadannan abubuwa da wayarka ta yi, tsarin “Broadcast Receiber” ne suka sarrafata don aiwatar da su. Kana so ko ba ka so, dole sai haka ta faru.
Wannan tsari na “Broadcast Receiber” yana da ginshikai guda biyu da ke tafiyar da shi. Ginshiki na farko shi ne bangaren da ke samar da tsarin fadakarwar. Wannan bangare shi ake kira “Broadcasters.” Shi ne tsarin da maginin manhajar ya tsofa a cikin wayar sadda yake gina manhajar. Cewa, “A duk sadda sakon tes ya shigo, ki sanar da mai wayar ta hanyar sautin da mai wayar ya zaba don a fadakar da shi shigowar sakon tes.” Wannan tsari yana gine ne a cikin manhajar wayar. Mai wayar ba ya iya ganin tsarin, domin ba abu ba ne da ke zahiri. Sai bangare na biyu ko ginshiki na biyu, wanda ke karbar sakon fadakarwa don ya fadakar. Wannan bangare shi ake kira “Receibers.” Su ne manhajojin da ke aikin fadakarwar. Su ma an shigar musu da tsarin ne, cewa “Duk sadda kuka samu sako daga bangaren ‘Broadcasters’ to, ku yi abu kaza.”
Application Contedt
Wannan shi ne tsarin da ke lura da mahallin masarrafai ko manhajar da ke wayar salula; daga budewa zuwa rufewa. Duk bayanan da suka gabata daga makon jiya zuwa bangaren farko na kasidar wannan mako, masu dauke da tsare-tsare irin su “Actibity,” da “Intent,” da “Serbices,” da “Content Probiders,” da kuma “Broadcast Receibers,” duk suna gudanuwa ne a cikin wani tsari mai kama da mazubi da ake kira “Application Contedt.” A karkashin wannan tsari, mai waya ba ya iya komai; tsarin ne ke tafiyar da kansa.
Wadannan, su ne mahimman bangarorin da suka kamata mai karatu ya fahimce su kafin mu shiga bayani kan Sarkin Gida, wato tsarin “Actibity Manager” kenan. Kamar yadda muka sani ne, bangarorin babbar manhajar wayar salula suna kamayya ne a tsakaninsu; wannan ya kama ya ba wannan; daga farkon tsarin har karshe. Kamar dai yadda bangarorin jikin dan Adam ke gudanuwa. A yanzu ga bayani kan tsarin “Actibity Manager.”
Actibity Manager
Kamar yadda bayani ya gabata a baya, tsarin “Actibity Manager” ne ke gudanar da dukkan abin da ke faruwa a wayar salula mai dauke da babbar manhajar Android. Tsari ne mai kyau, mai cike da tsari, don inganta yanayin gudanuwar ayyukan kowace manhaja da ke wayar. Idan kana son sanin wani tsari kwatankwacin wannan, don karin fahimta, to ka dubi tsarin “Task Manager” da ke tafiyar da manhajojin da ke gudanuwa a babbar manhajar Windows na kamfanin Microsoft.
Asalin fahimtar da ta samar da tsarin “Actibity Manager” na da alaka ce mai karfi da wacce ta samar da tsarin “Task Manager” na kwamfuta. Sai dai akwai bambanci tsakanin tsarinsu. A yayin da a manhajar Windows mai kwamfuta na iya sarrafawa da canza tsare-tsaren “Task Manager,” a fannin gina manhajar Android, mai wayar salula ba shi da kudira wajen iya gani ma, balle canza tsare-tsaren “Actibity Manager.” Idan mai karatu bai manta ba, a bangaren da na yi bayani kan “Manufar Gina Manhajar Android,” na nuna cewa daga manufofin akwai kokarin samar da sauki ga mai waya. Wannan manufa ce take kokarin rage wa mai waya yawan katsalandan da zai iya yi kan babbar manhajar. Sai aka kulle abubuwa da dama, wadanda ba zai iya kai wa gare su ba, balle ya iya sarrafa su ko canza su. Ba don komai ba sai don ganin cewa wadannan tsare-tsare da aka hana shi kai wa gare su, suna taimakawa wajen rage masa aiki ne, da kokarin samar masa da sauki wajen mu’amala da manhajojin da yake amfani dasu.
kari a kan haka, tsarin “Actibity Manager” ya fi inganci wajen tafiyar da manhaja, domin ya dauke wa mai waya alhakin ayyukan ne gaba daya. Wannan ke nuna wayar ba za ta samu matsala ba, domin tsarin da yake gundanar da ita, shi ne ke lura da ita har wa yau. Masana a fannin Android sun ba da misali da mota mai dauke da tsarin giya da ke sarrafa kansa, wato “Automatic Transmission System.” Injinta ya fi karko idan ka hada ta da injin wacce mai motar ne ke sanya giya da kansa, wato “Manual Gear System”; a duk lokacin da ya ga dama.
Yadda Actibity Manager ke Tafiyar da Aikinsa
Wannan tsari na “Actibity Manager” na tafiyar da ayyukansa ne cikin marhaloli guda biyar, kamar yadda bayani ya gabata a makon jiya. Wadannan marhaloli su ake kira “Actibity Lifecycle.” Duk da cewa bayani ya gabata cewa tsarin “Actibity” ne ke da wadannan marhaloli, sai dai sauran tsare-tsaren ma, duk suna cikin wannan tsari ne. A matsayinka na mai waya, da zarar ka kira wata manhaja, ko masarrafa misali, tsarin “Actibity Manager” zai gudanar maka da ita nan take, daga samarwa zuwa kashewa. Ga marhalolin da kowane tsarin “Actibity Manage r” ke bi wajen tafiyar da manhajojin wayar Android nan:
onCreate(), onStart()
Da zarar ka latsa wata manhaja da nufin budewa a wayarka, nan take Sarkin Gida (Actibity Manager) zai “rayar” maka da ita, ta hanyar loda manhajar, tare da bayanan da take aiki da su. Wannan marhalar farko kenan, kuma ita ce marhalar da ake kira “Starting State,” wato “Marhalar Rayuwa.” A wannan marhalar, zai yiwu kana matsa alamar manhajar nan take manhajar ta bude, ko kuma a dan samu jinkiri na dakika biyu ko uku kafin manhajar ta bude. Latsa manhajar da ka yi, ka bai wa tsarin “Actibity Manager” umarni ne ya rayar maka da manhajar. A yayin da ka latsa, nan take zai baiwa wayarka umarnin budo manhajar, ta hanyar tsarin gina manhajar kwamfuta guda biyu (Methods) da ake kira: “onCreate()” da “onStart()”. Wannan ita ce marhalar farko. Kuma ita ce marhalar da ta fi cin makamashin waya, saboda hidimar da wayar salula ke yi wajen samar wa wannan manhaja da ka latsa wurin zama, ta hanyar Sarkin Gida.
Marhala ta Biyu
Da zarar manhajar da ka latsa ta budo, to, an zo marhala ta biyu kenan. Wannan ita ce marhalar da ake kira “Running State,” wato “Marhalar Gudanuwa.” Misali, idan ka latsa manhajar sakonnin tes (Message App), shafin zai budo. Wannan shafi da ya budo kuma yake fuskantarka, ya kai mai mu’amala da waya, yana cikin yanayin mu’amala kenan, wato “In Focus,” a marhalar Gudanuwa. A tsarin mu’amala da babbar manhajar Android, yanayi daya kadai mai mu’amala da waya ke iya mu’amala da shi a lokaci guda. Wannan ba ya hana a samu wasu manhajojin da ke bude a lokacin. Da zarar ka latsa bangaren rubuta sakonnin tes a shafin wannan manhaja, wato “Compose,” nan take Sarkin Gida zai jefa uwar manhajar da ka budo zuwa marhala ta gaba.
onPaused()
Wannan ita ce marhalar “Dakatarwa,” wato “Paused State.” Kada mai karatu ya mance, har yanzu manhajar sakonnin tes da ya budo tana nan, amma bangaren da yake mu’amala da shi ne kadai (wato Compose) yake “Marhalar Gudanuwa.” daya bangaren kuma, wato gangar jiki manhajar tes din, duk da cewa shi ma a bude yake, sai dai ya fita daga marhalar gudanuwa zuwa marhalar dakatarwa; don ba da shi ake mu’amala ba yanzu. Idan ka gama rubuta sakonnin tes, sai ka dawo baya ka ci gaba da duba sakonnin da wasu suka aiko maka, to, sai a mayar da kai marhala ta baya, wato “Marhalar Gudanuwa,” ko “Running State.” Amma idan ka rufe manhajar gaba dayanta daga shafin da kake, sai Sarkin Gida ya zarce da kai marhala ta gaba.
onStop()
A halin yanzu ka rufe manhajar da ka budo a baya, nan take sai Sarkin Gida ya kira tsarin onStop() (wato onStop() Method Call), don tsayar da gudanuwar manhajar da ka budo a baya. Wannan ita ce marhalar “Tsayarwa.” Har yanzu manhajar ba ta fice daga jikin wayarka ba, duk da cewa ka daina ganinta a shafin wayar. A gare ka kam ta bace, amma a hakika, tana shige cikin marhala ta hudu ne, wato “Stop State.” Da zarar an samu wani lokaci mai dan tsawo ba ka sake kiran wannan manhaja da ka rufe dazu ba, sai Sarkin Gida ya wuce da ita marhala ta karshe.
onDestroy()
Marhala ta karshe ita ce marhalar “Kashewa”, wato “Destroy State.” A wannan marhala, Sarkin Gida ya kashe manhajar ce gaba dayanta daga gudanuwa, don samar wa wasu manhajojin da za ka iya budowa nan gaba mahallin gudanuwa. Wannan ita ce marhala ta karshe. Lokacin da Sarkin Gida zai kira tsarin onDestroy() (wato onDestroy() Method Call) don share dukkan bayanan da suka danganci wancan manhaja da ka rufe dazu, daga cikin kwakwalwa ko ma’adanar wayar.