Quantcast
Viewing all articles
Browse latest Browse all 8068

Titanium Android app stops at splash screen on restart

Questions

There are two questions here:

  1. Why does the NFC Tag Discovered event restart the Titanium app? (Android only)
  2. Why does the Titanium Android app stop at the splash screen when restarting?

Background

I have a simple app trying to read the unique tag ID in NFC cards.

Titanium has a module to provide the NFC support, so that part is covered. I have an alert to display the tag attributes when the Tag Discovered event is triggered.

However, when the app is launched on my Google Nexus 7 (which has NFC support), and I place an NFC card against the NFC sensor on the back of the machine, it triggers the Tag Discovered event but restarts the app and does not show the alert.

When the app restarts (immediately), it remains on the initial splash screen. and if the NFC card is touched to the sensor once more, the alert displays with the tag info.

So (1) why does the restart happen, and (2) why does it stop at the splash screen?

Additional Information

I also have tried this with tishadow, and the tishadow run --update command. Upon update, the app ALSO restarts, and stops at the splash screen, so I don't think the NFC module is the reason it stops at the splash screen (although I don't understand why the NFC trigger would restart the app).

I also have a native Java NFC application, partly done, running in Eclipse, which does not restart the app upon Tag Discovery.

I've tried the following: * Titanium project clean * making sure deploy.json is cleared

Thank you for any help anyone can provide!!

Environment

Application type: mobile

Titanium SDK: Titanium Command-Line Interface, CLI version 3.2.1, Titanium SDK version 3.2.1.v20140206170116

Platform & version: Android 4.1.2 (version 16)

Device: Google Nexus 7

Host Operating System: OSX 10.8

Titanium Studio: Titanium Studio, build: 3.2.1.201402041146

Code

Test case: on github at: https://github.com/btsai/card_reader, most relevant parts are:

tiapp.xml

<?xml version="1.0" encoding="UTF-8"?>
<ti:app xmlns:ti="http://ti.appcelerator.org">
  <id>me.tasi.cardreader</id>
  <name>CardReader</name>
  <version>1.0.0</version>
  <publisher>btsai</publisher>
  <url>http://tsai.me</url>
  <description>Felica card reader</description>
  <copyright>2014 by btsai</copyright>
  <icon>appicon.png</icon>
  <fullscreen>true</fullscreen>
  <navbar-hidden>false</navbar-hidden>
  <analytics>false</analytics>
  <guid>c16fd887-4a00-4856-9a48-c9cf8d3c357c</guid>
  <property name="ti.ui.defaultunit" type="string">dp</property>
  <android xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest>
        <uses-permission android:name="android.permission.NFC"/>
        <uses-sdk android:minSdkVersion="10"/>
        <uses-feature android:name="android.hardware.nfc" android:required="true"/>
        <application>
          <activity
            android:label="CardReader"
            android:name=".CardreaderActivity"
            android:configChanges="keyboardHidden|orientation"
            android:screenOrientation="portrait"
            android:launchMode="singleTask"
            android:theme="@style/Theme.Titanium"
          >
            <intent-filter>
              <action android:name="android.intent.action.MAIN"/>
              <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
              <action android:name="android.nfc.action.TAG_DISCOVERED"/>
              <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
          </activity>
      </application>
    </manifest>
  </android>
  <mobileweb>
    <precache/>
    <splash>
      <enabled>false</enabled>
      <inline-css-images>true</inline-css-images>
    </splash>
    <theme>default</theme>
  </mobileweb>
  <modules>
    <module platform="iphone">com.appcelerator.urlSession</module>
    <module platform="android">ti.nfc</module>
  </modules>
  <deployment-targets>
    <target device="android">true</target>
    <target device="blackberry">false</target>
    <target device="ipad">false</target>
    <target device="iphone">false</target>
    <target device="mobileweb">false</target>
    <target device="tizen">false</target>
  </deployment-targets>
  <sdk-version>3.2.1.v20140206170116</sdk-version>
  <plugins>
    <plugin version="1.0">ti.alloy</plugin>
  </plugins>
</ti:app>

And index.js

var nfc = null;
var nfcAdapter = null;
var dispatchFilter = null;
 
$.index.addEventListener('open', function(e) {
  nfc = require('ti.nfc');
  if (nfc){
    setupNfc();
  }
  else {
    $.warning.text = 'nfc module is not loaded on this device';
    alert($.warning.text);
  }
});
 
$.index.open();
 
function setupNfc() {
  nfcAdapter = nfc.createNfcAdapter({
    onTagDiscovered: handleTagDiscovery,
  });
 
  if (!nfcAdapter.isEnabled()) {
    $.warning.text = 'NFC is not enabled on this device';
    return;
  }
 
  var act = Ti.Android.currentActivity;
  act.addEventListener('newintent', function(e) {
    nfcAdapter.onNewIntent(e.intent);
  });
}
 
function handleTagDiscovery(e){
  alert('Tag discovered: ' + JSON.stringify(e.tag));
}
Logs:

From Android Debug Monitor

03-20 18:12:53.875: I/ActivityManager(480): START u0 {flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras)} from pid 23903
03-20 18:12:53.905: I/ActivityManager(480): START u0 {act=android.nfc.action.TAG_DISCOVERED cmp=me.tasi.cardreader/.CardreaderActivity (has extras)} from pid 23903
03-20 18:12:53.915: W/InputMethodManagerService(480): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@419c4ef0 attribute=null, token = android.os.BinderProxy@4176c010
03-20 18:12:54.035: I/ActivityManager(480): Displayed me.tasi.cardreader/.CardreaderActivity: +14s798ms (total +137ms)

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>