Android Question App launched through intent closes when leaving foreground

pixsys

Member
Licensed User
Longtime User
Hello
I'm working on an NFC app, so i added the ability to launch the app by tapping a nfc tag.

All works good, thing is when launched throu a "tap", the app cannot go into background, it will automatically die when anything makes it leave the foreground.

On a couple devices with android <5, it will die as soon as the task manager soft button is pressed, on another device running android 5, the task manager can be opened (and instead of my name/icon, i see "NFC SERVICE" with the nfc icon) but the app will die if another app is sent to the foreground

From my manifest:
B4X:
AddActivityText(Main, <intent-filter>
    <action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>)

AddActivityText(Main,<meta-data
                android:name="android.nfc.action.TECH_DISCOVERED"
                android:resource="@xml/tech_filter" />
)

and this is the filter:
B4X:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <tech-list>
        <tech>android.nfc.tech.NfcV</tech>    
    </tech-list>
</resources>

Any idea on why does this happen?
Thanks
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Quick and dirty idea : pointing the intent filter to a service instead of the Activity
 
Upvote 0

pixsys

Member
Licensed User
Longtime User
Thanks for the replies:

Quick and dirty idea : pointing the intent filter to a service instead of the Activity
Wouldn't that only affect the launch but not the app lifecycle?


Does it crash when it move to the background?

The OS is allowed to kill applications that move to the background. This is normal.
Seems like it doesnt, no errors or anything, it just dies...i know the OS can kill apps, but it happens every time, and only if started from an intent (no other apps in the task manager, so android doesnt really need to free resources).

Tried putting some code in service_destroy and application_error but it never gets executed
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Wouldn't that only affect the launch but not the app lifecycle?
I don't think so (but I am not not sure by the way, reason why you could make a quick test). What I am thinking is that the app is destroyed (as Erel said) because the Activity is sent to back (in Pause) and the device could need more resources in a short time.
 
Upvote 0

Paul Edwards

Member
Licensed User
Longtime User
Does it crash when it move to the background?

The OS is allowed to kill applications that move to the background. This is normal.
Can apps be closed programmatically when they go into the background. Is that how I can stop Spotify from playing?

Paul
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Is that how I can stop Spotify from playing?
1. You should always start a new thread for your questions. Posting to a 3 Years old Thread is a mistake.
2. Spotify has an Api which you should use i guess.
3. You can not control other apps unless they support it by implementing Intents. You do not have the rights to kill another app.
 
Upvote 0
Top