Results 1 to 5 of 5

Thread: Handling deviceready in controller

  1. #1
    Sencha User
    Join Date
    Dec 2009
    Posts
    425
    Answers
    2

    Default Answered: Handling deviceready in controller

    Hi,
    When I need to use a cordova plugin, I listen for the deviceready event.
    In all examples I have seen so far, the event and its handler are registered in app.js' launch function.
    Is there a way to put the handler in a controller so that I can use the plugin from the controller?
    Basically I want my controller to be notified/launch function called when the deviceready event fires.

    Please help.

  2. This is correct. We detect if you are within a Cordova/PhoneGap app and then add a deviceready listener. The application's launch method (and therefore the controllers' launch methods) will not execute until the deviceready event has already been fired.

  3. #2
    Sencha User
    Join Date
    Dec 2009
    Posts
    425
    Answers
    2

    Default

    Looks like you don't need to listen to deviceready.The main controller's launch function will be called after deviceready is fired.
    Can others confirm this?

  4. #3
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,449
    Answers
    3997

    Default

    This is correct. We detect if you are within a Cordova/PhoneGap app and then add a deviceready listener. The application's launch method (and therefore the controllers' launch methods) will not execute until the deviceready event has already been fired.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Fullstack Engineer
    ________________
    Modus Create is based on the model of an open source team. We’re a remote, global team of experts in our field. To find out more about the work we do, head over to our website.

    Check out my GitHub:
    https://github.com/mitchellsimoens

  5. #4
    Sencha Premium Member
    Join Date
    Mar 2015
    Posts
    1

    Default

    If this is true then why am I hitting the callback of deviceReady listener inside my launch function?

    Code:
    launch: function () {
        document.addEventListener('deviceready', this.__onDeviceReady.bind(this), false);
    },

  6. #5
    Sencha Premium Member
    Join Date
    Oct 2011
    Location
    Duluth, MN
    Posts
    154
    Answers
    3

    Default

    Quote Originally Posted by shr View Post
    If this is true then why am I hitting the callback of deviceReady listener inside my launch function?

    Code:
    launch: function () {
        document.addEventListener('deviceready', this.__onDeviceReady.bind(this), false);
    },

    This is because deviceready fires immediately if cordova is already ready. It's a nice feature that lets you add deviceready handlers that will fire even if cordova is already completed.

Similar Threads

  1. MVC: handling link clicks in the controller
    By a_arias in forum Ext: Discussion
    Replies: 6
    Last Post: 21 May 2013, 2:39 AM
  2. Controller -- sub-classing and event handling.
    By santosh.kumar in forum Ext: Q&A
    Replies: 2
    Last Post: 19 Feb 2013, 11:41 AM
  3. Problem with handling events in controller.
    By zozo4kin in forum Sencha Touch 2.x: Q&A
    Replies: 7
    Last Post: 14 May 2012, 6:32 AM
  4. Controller handling in sencha 2 ?
    By fenderico in forum Sencha Touch 2.x: Q&A
    Replies: 2
    Last Post: 9 Mar 2012, 8:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •