Warning Older Docs! - You are viewing documentation for a previous released version of RhoMobile Suite.

AppApplication API

RUBY RHOELEMENTS RHODES 

Coordinate the startup of a Rhodes application. These methods are in the application.rb file.

initialize

The initialize method is generated in the application.rb file. Put your application initialization code here.

class AppApplication < Rho::RhoApplication
  def initialize
    # put initialization code here
  end
end

AppApplication Class Methods

You can define the following AppApplication class methods in your application.rb file to listen for activation, deactivation, and upgrade events:

  • on_ui_created
  • on_ui_destroyed
  • on_activate_app
  • on_deactivate_app
  • on_reinstall_config_update

on_ui_created

Write the on_ui_created method in the application.rb file to run code after your application’s UI is created (such as at application start).

def on_ui_created
  # put your application UI creation code here
  # for example, create tab bar:
  # NativeBar.create(Rho::RhoApplication::TABBAR_TYPE, tabs)

  super # To navigate to start_path from rhoconfig.txt
end

on_ui_destroyed

Write the on_ui_destroyed method in the application.rb file to run code after your application’s UI is destroyed (such as at application exit).

def on_ui_destroyed
# put your code here
# example:
# @forbid_ui_operations = true
end

on_activate_app

Write the on_ui_destroyed method in the application.rb file to run code after your application is activated.

def on_activate_app
# put your application activation code here
end 

on_deactivate_app

Write the on_ui_destroyed method in the application.rb file to run code before your application goes to the background. Don’t call any UI operations here, they’ll be ignore (for example, WebView.refresh).

def on_deactivate_app
  # to stop sync background thread call 
  # SyncEngine.stop_sync; SyncEngine.set_pollinterval(0)

  # To stop local web server when application switched to 
  # background return "stop_local_server"
  # return "stop_local_server" 
end 

on_reinstall_config_update

Write the on_reinstall_config_update method in the application.rb file to run code when your application is upgraded.

conflicts is a hash name to an array of conflicted values (old local value, new upgrade value) for any conflicts for the properties in rhoconfig.txt. By default, the local values are kept in place, but you may overwrite them with new values in the conflicts array.

def on_reinstall_config_update(conflicts)
  # puts "on_reinstall_config_update: #{conflicts}"
end
Back to Top