Simple app shutdown automatically on Android device

You must Login before you can answer or comment on any questions.

I've installed my simple demo app (empty project with single window template) via USB on my android device. When I start the app I'll see the titanium splash, then the window of the app appears very quickly and after that the app shutdown automatically. Can anybody help me with this behaviour?

— asked 7 months ago by Alexander Stark
2 Comments
  • I don't think that's enough information for any help - try running DDMS and checking output logs for more data

    — commented 7 months ago by Ken Liu

  • I see this message in DDMS:

    10-23 17:29:44.039: D/TiUIView(3452): (main) [73,780] Nativeview is null

    — commented 7 months ago by Alexander Stark

4 Answers

Accepted Answer

HI Alexander, i just created a single window application in titanium and it shows the the file and function structure you are using and presenting here... i run it on both the systems.. iOS and android. it runs without error.

so you can try that too... create a default single window application and run on android... i tried on both android emulator and device..

— answered 7 months ago by Ashish Nigam
answer permalink
7 Comments
  • Which version of Android and which device do you use?

    — commented 7 months ago by Alexander Stark

  • Now I have a second device. A HTC Desire with Android 2.2.2 and it works. It would be intersting what component is the problem. Android 4.0.3 or LG-P700

    — commented 7 months ago by Alexander Stark

  • hmm, i tested on android 4.0.3 device but name i forgot as i borrowed from one of my friend to test it.

    — commented 7 months ago by Ashish Nigam

  • Show 4 more comments

You're doing something funny there :) post the code in a pastie and show us what u're doing.

I have no special code. Just a new created project of the template "Single Window Application". Here it is: app.js:

/*
 * Single Window Application Template:
 * A basic starting point for your application.  Mostly a blank canvas.
 * 
 * In app.js, we generally take care of a few things:
 * - Bootstrap the application with any data we need
 * - Check for dependencies like device type, platform version or network connection
 * - Require and open our top-level UI component
 *  
 */
 
//bootstrap and check dependencies
if (Ti.version < 1.8 ) {
    alert('Sorry - this application template requires Titanium Mobile SDK 1.8 or later');       
}
 
// This is a single context application with mutliple windows in a stack
(function() {
    //determine platform and form factor and render approproate components
    var osname = Ti.Platform.osname,
        version = Ti.Platform.version,
        height = Ti.Platform.displayCaps.platformHeight,
        width = Ti.Platform.displayCaps.platformWidth;
 
    //considering tablet to have one dimension over 900px - this is imperfect, so you should feel free to decide
    //yourself what you consider a tablet form factor for android
    var isTablet = osname === 'ipad' || (osname === 'android' && (width > 899 || height > 899));
 
    var Window;
    if (isTablet) {
        Window = require('ui/tablet/ApplicationWindow');
    }
    else {
        // Android uses platform-specific properties to create windows.
        // All other platforms follow a similar UI pattern.
        if (osname === 'android') {
            Window = require('ui/handheld/android/ApplicationWindow');
        }
        else {
            Window = require('ui/handheld/ApplicationWindow');
        }
    }
    Ti.API.info('app.js open window');
    new Window().open();
    Ti.API.info('app.js window opened');
})();
ui\handheld\android\ApplicationWindow.js
//Application Window Component Constructor
function ApplicationWindow() {
    Ti.API.info('ApplicationWindow ENTER');
    //load component dependencies
    var FirstView = require('ui/common/FirstView');
 
    //create component instance
    var self = Ti.UI.createWindow({
        backgroundColor:'#ffffff',
        navBarHidden:true,
        exitOnClose:true
    });
 
    //construct UI
    var firstView = new FirstView();
    self.add(firstView);
 
    Ti.API.info('ApplicationWindow LEAVE');
    return self;
}
 
//make constructor function the public component interface
module.exports = ApplicationWindow;
ui\commonFirstView.js
//FirstView Component Constructor
function FirstView() {
    Ti.API.info('FirstView ENTER');
 
    //create object instance, a parasitic subclass of Observable
    var self = Ti.UI.createView();
 
    //label using localization-ready strings from <app dir>/i18n/en/strings.xml
    var label = Ti.UI.createLabel({
        color:'#000000',
        text:String.format(L('welcome'),'Titanium'),
        height:'auto',
        width:'auto'
    });
    self.add(label);
 
    //Add behavior for UI
    label.addEventListener('click', function(e) {
        alert(e.source.text);
    });
 
    Ti.API.info('FirstView LEAVE');
    return self;
}
 
module.exports = FirstView;
There are no changes in automatically generated code

Your Answer

Think you can help? Login to answer this question!