Kivy Android app running in background crashes when intent tries to pull it to top
See original GitHub issue@EmmaCaunter commented on May 4, 2018, 6:17 PM UTC:
Versions
- Python: 2.7
- OS: Android
- Kivy: master
- Kivy installation method: Git
Description
When the app is in the background, I want to use Android’s Intent to bring app back to top. When the intent activates, the app instantly crashes and then restarts. This issue occurs with the new toolchain but not with the old one.
Code and Logs
Code to replicate:
***************
from kivy.app import App
from kivy.uix.button import Button
from android.broadcast import BroadcastReceiver
from jnius import autoclass
from plyer.platforms.android import SDK_INT
PythonActivity = autoclass('org.kivy.android.PythonActivity')
NotificationBuilder = autoclass('android.app.Notification$Builder')
Context = autoclass('android.content.Context')
Intent = autoclass('android.content.Intent')
PendingIntent = autoclass('android.app.PendingIntent')
Uri = autoclass('android.net.Uri')
Notification = autoclass('android.app.Notification')
AndroidString = autoclass('java.lang.String')
class TestApp(App):
def build(self):
return Button(text='Hello World')
def on_resume(self):
print "On resume"
def on_pause(self):
print "on pause"
activity = PythonActivity.mActivity
Drawable = autoclass("{}.R$drawable".format(activity.getPackageName()))
notification_service = activity.getSystemService(Context.NOTIFICATION_SERVICE)
icon = getattr(Drawable, 'icon')
noti = NotificationBuilder(activity)
noti.setPriority(Notification.PRIORITY_MAX)
noti.setDefaults(Notification.DEFAULT_ALL)
noti.setContentTitle(AndroidString(("title").encode('utf-8')))
noti.setContentText(AndroidString(("message").encode('utf-8')))
noti.setSmallIcon(icon)
id = 22701
app_intent = Intent(Intent.ACTION_PROVIDER_CHANGED)
pending_intent = PendingIntent.getBroadcast(activity, id, app_intent, PendingIntent.FLAG_UPDATE_CURRENT)
app_intent.setData(Uri.parse('close'))
if not hasattr(self, 'br'):
self.broadcast_receiver = BroadcastReceiver(
self.on_broadcast, actions=['provider_changed', 'run'])
self.broadcast_receiver.start()
noti.addAction(0, AndroidString("Start"), pending_intent)
if SDK_INT >= 16:
noti = noti.build()
else:
noti = noti.getNotification()
notification_service.notify(0, noti)
return True
def on_broadcast(self, context, intent):
print "On Broadcast"
activity = PythonActivity.mActivity
notification_service = activity.getSystemService(Context.NOTIFICATION_SERVICE)
notification_service.cancel(0)
intent = Intent(activity.getApplicationContext(), PythonActivity)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
activity.getApplicationContext().startActivity(intent)
TestApp().run()
**************
Put app into background, which triggers notification. Touch notification to re-open app, and the app crashes with the following error:
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x4 in tid 7199 (SDLThread)
More detailed logging reveals the following SIGSEGV fingerprint:
04-30 15:53:41.350 3138-3269/? I/bt-btm: BTM_CheckAdvData type=0x19
04-30 15:53:41.350 3138-3269/? I/bt-btm: BTM_CheckAdvData type=0x03
04-30 15:53:41.350 3138-3269/? D/bt-btm: BR/EDR NOT support bit not set, treat as DUMO
04-30 15:53:41.350 458-458/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-30 15:53:41.350 458-458/? I/DEBUG: Build fingerprint: 'htc/bm/htc_m8:5.0.1/LRX22C/463267.2:user/release-keys'
04-30 15:53:41.350 458-458/? I/DEBUG: Revision: '0'
04-30 15:53:41.350 458-458/? I/DEBUG: ABI: 'arm'
04-30 15:53:41.350 458-458/? I/DEBUG: pid: 9964, tid: 10051, name: SDLThread >>> com.test.example <<<
04-30 15:53:41.360 458-458/? I/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x4
04-30 15:53:41.360 458-458/? I/DEBUG: r0 a0e3e108 r1 a0e3e108 r2 fffffc7c r3 00000000
04-30 15:53:41.360 458-458/? I/DEBUG: r4 00000001 r5 97eb9ae8 r6 9dd4ee40 r7 00000001
04-30 15:53:41.360 458-458/? I/DEBUG: r8 00000001 r9 97eb9ae8 sl 00000001 fp b3e620c0
04-30 15:53:41.360 458-458/? I/DEBUG: ip a0e5fb00 sp 97eb5810 lr a0da36f9 pc a0da31dc cpsr 600b0030
04-30 15:53:41.370 458-458/? I/DEBUG: backtrace:
04-30 15:53:41.370 458-458/? I/DEBUG: #00 pc 000c61dc /data/app/com.test.example-1/lib/arm/libpython2.7.so (PySys_GetObject+11)
04-30 15:53:41.370 458-458/? I/DEBUG: #01 pc 000c66f5 /data/app/com.test.example-1/lib/arm/libpython2.7.so (PySys_SetArgvEx+84)
04-30 15:53:41.440 3138-3269/? I/bt-hci: BLE HCI(id=62) event = 0x02)
04-30 15:53:41.440 3138-3269/? I/bt-hci: btu_ble_process_adv_pkt
04-30 15:53:41.440 3138-3269/? D/bt-btm: btm_ble_process_adv_pkt:bda= 28:39:5e:4f:c9:b7
This issue was moved by tshirtman from kivy/kivy/issues/5728.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Kivy Android app running in background crashes when intent ...
Kivy Android app running in background crashes when intent tries to pull it to top.
Read more >Why my KivyMD app Crashes On Startup after converting to ...
android.permissions = INTERNET. Then it should work on android device. If it still crashes, you need to check your code by debugging.
Read more >How To Stop Kivy App From Crashing On Android - YouTube
Check out the cool simple steps to take to stop your kivy app from crashing on android.
Read more >A Simple Paint App — Kivy 2.1.0 documentation
If you want to write a very simple line drawing application for example, ... Try to write them in a minimal and reusable...
Read more >How to crash an Android application manually - Quora
The best and the easiest way to crash an Android app is to make a DivideByZero exception. In the onCreate method of your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry to not have answer before, indeed look like fixed with various SDL2.0.9 or master…
Thanks @EmmaCaunter for the clear example, it would have been much harder to debug without it.