Titanium JIRA Archive
Appcelerator Community (AC)

[AC-3549] OnLifecycleEvent doesn't work on viewproxy

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNot Our Bug
Resolution Date2016-04-28T04:24:22.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
LabelsAndroid, Module
ReporterRainer Schleevoigt
AssigneeShak Hossain
Created2016-04-26T08:06:50.000+0000
Updated2016-04-28T04:24:22.000+0000

Description

Hi, in my special view I need access to lifecycle events for rerendering etc. The only example I found in net is https://github.com/appcelerator-modules/ti.admob/blob/master/android/src/ti/admob/ViewProxy.java My viewproxy is a simple clone of it: https://github.com/AppWerft/Ti.AudioVisualizerView/blob/master/android/src/ti/audiovisualizerview/ViewProxy.java The event never appears. If I add the init routine in view constructor, then I see the visualizer, but not after resuming. Does the event listener depends of a condition? The module will called after open event of window

Comments

  1. Rainer Schleevoigt 2016-04-26

    The same issue, if I add the code to native View: https://github.com/AppWerft/Ti.AudioVisualizerView/blob/master/android/src/ti/audiovisualizerview/VisualizerImageView.java
  2. Rainer Schleevoigt 2016-04-26

    Here the code example:
       var $ = Ti.UI.createWindow();
       $.addEventListener('open', function() {
         require('vendor/permissions').requestPermissions(['RECORD_AUDIO', 'MODIFY_AUDIO_SETTINGS'], function(_success) {
           if (_success == true) {
             var Visualizer = require('ti.audiovisualizerview');
             $.visualizerView = Visualizer.createView({
               audioSessionId : 0, //playStopControlView.audioSessionId || 0,
             });
             $.visualizerView.addEventListener('ready', function() {
             $.visualizerView.addBarGraphRenderers();
       });
       	$.add($.visualizerView); 
       } else
       		console.log('Pheelicks: WRONG PERMISSIONS');
       });
       });
       $.open();
       
  3. Nazmus Salahin 2016-04-26

    Hello, Thanks for your query. Here is some information which may help you. On android lifecycle events are attached to activities. For example onPause event of an activity is fired when the activity is paused. To make a proxy to respond to these events first, in the module proxy, override the activity lifecycle callbacks you want to respond to. Then, in the JavaScript application, when you create the module proxy, assign its lifecycleContainer property to either a Window or TabGroup object to listen for that object's lifecycle events to trigger the module proxy's activity lifecycle callbacks. Like this :
       var win = Ti.UI.createWindow();
       var foo = require('com.appc.foo');
       var fooProxy = foo.createExample({lifecycleContainer: win});
       win.open();
       
       
    [Documentation Link](http://docs.appcelerator.com/platform/latest/#!/guide/Android_Module_Architecture-section-43289000_AndroidModuleArchitecture-ActivityLifecycleEvents) Thanks
  4. Rainer Schleevoigt 2016-04-26

    Thanks for quick answer. In my case the calling of module is after opening of window. Is it a problem? Second: I found in TiUIImageView.java the same pattern. The listener is binded an View, not on Viewproxy and in JS-code I dont see the lifecycle binding. Or is it only needed for special applications? Is there a difference TiContext.OnLifecycleEvent;and and TiLifecycle.OnLifecycleEvent? Cheers!
  5. Nazmus Salahin 2016-04-26

    Hello, First: When the window is opened the activity has already gone pass onResume and onStart event. You can not catch these events now. But the the activity can go through these events again depending on the app structure. Second: While developing module you have to make use of module development API. [LINK](http://docs.appcelerator.com/module-apidoc/latest/android/index.html) Thanks

JSON Source