Skip to content
  • Home
  • Agro
    • Agro
    • Akuaponik
    • Hidroponik
    • Ayam Kampung
  • DIY
    • DIY
    • Rumah Kampung
  • Tech
    • Tech
    • Titanium Mobile
  • Media
    • Media
    • Downloads
    • Dashcam Drive
  • Misc
    • Pelbagai
    • Makanan
    • Fotografi
    • Idea
    • E-mau
  • Home
  • Agro
    • Agro
    • Akuaponik
    • Hidroponik
    • Ayam Kampung
  • DIY
    • DIY
    • Rumah Kampung
  • Tech
    • Tech
    • Titanium Mobile
  • Media
    • Media
    • Downloads
    • Dashcam Drive
  • Misc
    • Pelbagai
    • Makanan
    • Fotografi
    • Idea
    • E-mau
blog.azwan082.my


Blog ini tidak lagi dikemaskini, sila ke
👉 azwan082.my 👈
untuk dapatkan kandungan terbaru.

#CommonJS  #Javascript  #Titanium Mobile

Indirect code execution flow

On 12 September 2013 in Tech

Intro: we have an Android app, with typical main and detail window structure.

Let’s see this situation: when user tap a button on main window and then open a detail window, later when user closes the detail window, it needs to update the main window UI.

Here, we have two method of how to update the UI – proactive / direct way, or passive / indirect way.

First, there are several point during detail window closing process, which we can run the function to update the main window UI.

  • when user press back button on detail window
  • when detail window close event
  • when main window resumed

Direct way – when running the function to update main window UI during the 1st and 2nd point above.

// in detail window class

detailWindow.addEventListener('androidback', function() {
	mainWindow.updateUI();
	detailWindow.close();
});

// or

detailWindow.addEventListener('close', function() {
	mainWindow.updateUI();
});

Some disadvantages for this method:

  • detail window need to keep a reference to main window.
  • if updateUI() function take some time, then closing detail window will be delayed

Therefore, to ensure responsiveness of the app, we need to utilize indirect way of executing the code. When main window resume, we run the code to update the UI. But, what if we need to update the UI only when user close the detail window? Here, we need a state variable (variable that keeps track of a state).

// in main window class

var detailWindowOpened = false;
btn.addEventListener('click', function() {
	detailWindowOpened = true;
	detailWindow.open();
});

detailWindowOpened is the state variable, it tracks whether detail window has been opened or not.

// in main window class

mainWindow.activity.addEventListener('resume', function() {
	if (detailWindowOpened) {
		updateUI();
		detailWindowOpened = false;
	}
});

Then, when main window resume, it will automatically update its UI. So here, we don’t need to keep a reference of main window inside detail window class, and closing detail window won’t be delayed.

Share this post:
  • Share
  • Tweet
  • LinkedIn

Related posts:

  • Android BOOT_COMPLETED handler module
  • Ti.Network.registerForPushNotifications no response
  • Enable x86 libs in production build Titanium app
  • Webview evalJS return null in Android 4.2.2
  • Titanium iOS “build” is an unrecognized command
  • Titanium app hex color value with alpha channel
  • Efficient code
  • Titanium Studio unbound classpath container error
  • JS parseBool()
  • Object oriented Javascript with CommonJS in Titanium app

Filed under Tech with tags CommonJS, Javascript, Titanium Mobile

Post navigation

Previous Post Previous post:
WrestleMania 19
Next Post Next post:
Titanium iOS “build” is an unrecognized command

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Media sosial

  • facebook
  • instagram
  • twitter
  • pinterest
  • youtube

Carian

Artikel popular

  • Saiz standard kayu, papan dan plywood
  • Pemasangan dinding plywood rumah kampung secara solo
  • Kepincangan dalam menggunakan paip PVC sebagai saluran NFT hidroponik
  • 3 Jenis Asas Sistem Hidroponik Yang Digunakan Dalam Akuaponik Serta Variasinya
  • Cara membuat sistem NFT untuk akuaponik – Saliran masuk
  • Cara pasang pintu rumah
  • Jenis skru kayu
  • Larutan nutrien hidroponik DIY

Artikel terkini

  • 2 video #emau dari 2020/0221 February 2020
  • Gaya hidup minimalis14 February 2020
  • How to sync Mac OS Photos Library to an external disk storage17 January 2020
  • Sejarah dividen KWSP10 January 2020
  • Sejarah dividen Tabung Haji10 January 2020
  • Sejarah dividen ASB10 January 2020
  • Selamat dekad baru 2020-an3 January 2020
  • Dashcam Drive #17 – Taman Danu Serian → Ranchan Recreational Park1 January 2020

Tag

1N2D Akuaponik Android Apache Ayam Kampung Bash C# Cache Cili CommonJS Controller Dashcam Drive E-mau Fedora Fotografi Git Gnome Happy Together Hidroponik Idea Invincible Youth iOS Java Javascript Ke Indonesia Ke Kita? Ke Jepun Ke Kita? Ke Korea Ke Kita? Kewangan ListView Makanan Mr. Bean PHP Python Rant Roundtable Plus RPM Rumah Kampung Star Golden Bell Subversion SVN Titanium Mobile Titanium Module Titanium Studio windows phone WrestleMania

Arkib

Perihal

@azwan082

Seorang pembangun perisian (software developer) untuk peranti mudah alih (mobile devices) dan laman web, menggunakan bahasa pengaturcaraan Swift (iOS), Java (Android), PHP, MySQL dan Javascript (aplikasi web). Blog ini adalah tempat untuk saya berkongsi perkara, minat dan projek sampingan, seperti berkebun, kerja² kayu DIY, video dashcam drive dan pelbagai lagi.

© 2021 blog.azwan082.my

Back to top
sponsored