Inspired by TraceTogether and written in response to COVID19. OpenTrace is an application that can record user data and detect the presence of other BLE handsets and devices
MIT License
23
stars
14
forks
source link
Resolving AndroidRuntimeException on click of options menu in a real … #55
Issue:android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Solution:
We can use startActivity() from the Activity's context.
Steps to Reproduce:
Installed in the real device OS 6.0.1 and clicked the options menu Notification Settings.
StackTrace:
05-05 13:38:06.463 6072-6078/? I/art: Debugger is no longer active
05-05 13:38:06.475 6072-6072/? W/System: ClassLoader referenced unknown path: /data/app/ai.kun.socialdistancealarm-1/lib/arm
05-05 13:38:06.552 6072-6088/? I/DynamiteModule: Considering local module com.google.android.gms.measurement.dynamite:13 and remote module com.google.android.gms.measurement.dynamite:0
05-05 13:38:06.552 6072-6088/? I/DynamiteModule: Selected local version of com.google.android.gms.measurement.dynamite
05-05 13:38:06.574 6072-6094/? W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
05-05 13:38:06.612 6072-6098/? W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
05-05 13:38:06.630 6072-6098/? I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
05-05 13:38:06.657 6072-6072/? I/FirebaseCrashlytics: Initializing Crashlytics 17.0.0
05-05 13:38:06.712 6072-6072/? I/FirebaseInitProvider: FirebaseApp initialization successful
05-05 13:38:06.799 6072-6072/? D/BluetoothGattServer: registerCallback()
05-05 13:38:06.799 6072-6072/? D/BluetoothGattServer: registerCallback() - UUID=31b11051-e59f-40c7-a293-c053ebab7c7b
05-05 13:38:06.801 6072-6083/? D/BluetoothGattServer: onServerRegistered() - status=0 serverIf=6
05-05 13:38:06.824 6072-6099/? V/FA: App measurement collection enabled
05-05 13:38:06.827 6072-6099/? V/FA: App measurement enabled for app package, google app id: ai.kun.socialdistancealarm, 1:880225028168:android:b60e714e6bd88267eb307d
05-05 13:38:06.840 6072-6099/? I/FA: App measurement initialized, version: 26001
05-05 13:38:06.840 6072-6099/? I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
05-05 13:38:06.840 6072-6099/? I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app ai.kun.socialdistancealarm
05-05 13:38:06.840 6072-6099/? D/FA: Debug-level message logging enabled
05-05 13:38:06.846 6072-6072/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-05 13:38:06.854 6072-6088/? V/FA: onActivityCreated
05-05 13:38:06.881 6072-6072/? I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
05-05 13:38:06.881 6072-6072/? I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
05-05 13:38:06.917 6072-6099/? V/FA: Connecting to remote service
05-05 13:38:06.938 6072-6099/? V/FA: Connection attempt already in progress
05-05 13:38:07.133 6072-6099/? V/FA: Activity resumed, time: 22277057
05-05 13:38:07.142 6072-6132/? D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
05-05 13:38:07.151 6072-6099/? I/FA: Tag Manager is not found and thus will not be used
05-05 13:38:07.185 6072-6099/? V/FA: Connection attempt already in progress
05-05 13:38:07.186 6072-6099/? V/FA: Connection attempt already in progress
05-05 13:38:07.209 6072-6132/? I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: (Ifd751822f5)
OpenGL ES Shader Compiler Version: XE031.06.00.05
Build Date: 01/26/16 Tue
Local Branch: AU12_SBA
Remote Branch:
Local Patches:
Reconstruct Branch:
05-05 13:38:07.211 6072-6132/? I/OpenGLRenderer: Initialized EGL, version 1.4
05-05 13:38:07.300 6072-6072/? D/HomeFragment: Requested user enable Location.
05-05 13:38:07.489 6072-6099/ai.kun.socialdistancealarm D/FA: Connected to remote service
05-05 13:38:07.490 6072-6099/ai.kun.socialdistancealarm V/FA: Processing queued up service tasks: 4
05-05 13:38:07.619 6072-6099/ai.kun.socialdistancealarm V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 361
05-05 13:38:07.622 6072-6099/ai.kun.socialdistancealarm V/FA: Activity paused, time: 22277418
05-05 13:38:07.731 6072-6072/ai.kun.socialdistancealarm W/HomeFragment: ...Request for background location was denied.
05-05 13:38:07.735 6072-6099/ai.kun.socialdistancealarm V/FA: Activity resumed, time: 22277659
05-05 13:38:09.953 6072-6072/ai.kun.socialdistancealarm D/BluetoothAdapter: STATE_ON
05-05 13:38:09.957 6072-6083/ai.kun.socialdistancealarm D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
05-05 13:38:09.965 6072-6072/ai.kun.socialdistancealarm D/BLEClient: +++++++Started scanning.
05-05 13:38:10.784 6072-6072/ai.kun.socialdistancealarm D/BluetoothGattServer: addService() - service: d2b86f9a-264e-3ac6-838a-0d00c1f549ed
05-05 13:38:10.786 6072-6083/ai.kun.socialdistancealarm D/BluetoothGattServer: onServiceAdded() - service=d2b86f9a-264e-3ac6-838a-0d00c1f549edstatus=0
05-05 13:38:10.789 6072-6072/ai.kun.socialdistancealarm D/BluetoothAdapter: STATE_ON
05-05 13:38:10.796 6072-6083/ai.kun.socialdistancealarm D/BluetoothLeAdvertiser: onClientRegistered() - status=0 clientIf=8
05-05 13:38:10.825 6072-6072/ai.kun.socialdistancealarm D/BLEServer: >>>>>>>>>>BLE Beacon Started
05-05 13:38:10.826 6072-6072/ai.kun.socialdistancealarm D/BLEServerAdCallback: Peripheral advertising started.
05-05 13:38:12.756 6072-6099/ai.kun.socialdistancealarm V/FA: Inactivity, disconnecting from the service
05-05 13:38:13.968 6072-6072/ai.kun.socialdistancealarm D/BluetoothAdapter: STATE_ON
05-05 13:38:13.978 6072-6072/ai.kun.socialdistancealarm D/BLEClient: -------Stopped scanning.
05-05 13:38:19.956 6072-6072/ai.kun.socialdistancealarm D/BluetoothAdapter: STATE_ON
05-05 13:38:19.959 6072-6084/ai.kun.socialdistancealarm D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
05-05 13:38:19.965 6072-6072/ai.kun.socialdistancealarm D/BLEClient: +++++++Started scanning.
05-05 13:38:21.888 6072-6072/ai.kun.socialdistancealarm W/art: Before Android 4.1, method int androidx.appcompat.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
05-05 13:38:21.897 6072-6072/ai.kun.socialdistancealarm W/art: Before Android 4.1, method int androidx.appcompat.widget.MenuPopupWindow$MenuDropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
05-05 13:38:21.899 6072-6072/ai.kun.socialdistancealarm I/ListPopupWindow: Could not find method setEpicenterBounds(Rect) on PopupWindow. Oh well.
05-05 13:38:22.788 6072-6072/ai.kun.socialdistancealarm D/AndroidRuntime: Shutting down VM
05-05 13:38:22.879 6072-6099/ai.kun.socialdistancealarm V/FA: Connecting to remote service
05-05 13:38:22.889 6072-6099/ai.kun.socialdistancealarm V/FA: Recording user engagement, ms: 15154
05-05 13:38:22.915 6072-6099/ai.kun.socialdistancealarm V/FA: Connection attempt already in progress
05-05 13:38:22.963 6072-6072/ai.kun.socialdistancealarm E/AndroidRuntime: FATAL EXCEPTION: main
Process: ai.kun.socialdistancealarm, PID: 6072
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:672)
at android.app.ContextImpl.startActivity(ContextImpl.java:659)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
at ai.kun.socialdistancealarm.MainActivity.onOptionsItemSelected(MainActivity.kt:109)
at android.app.Activity.onMenuItemSelected(Activity.java:2918)
at androidx.fragment.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:383)
at androidx.appcompat.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:219)
at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:109)
at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:109)
at androidx.appcompat.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:64)
at androidx.appcompat.widget.Toolbar$1.onMenuItemClick(Toolbar.java:207)
at androidx.appcompat.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:781)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:840)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:991)
at androidx.appcompat.view.menu.MenuPopup.onItemClick(MenuPopup.java:128)
at android.widget.AdapterView.performItemClick(AdapterView.java:310)
at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3073)
at android.widget.AbsListView$3.run(AbsListView.java:3910)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-05 13:38:25.201 6072-6101/ai.kun.socialdistancealarm I/FirebaseCrashlytics: Crashlytics Reports Endpoint upload complete: 5EB11EE602C7-0001-17B8-4231A7C0D622```
…device
Issue:
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Solution: We can use
startActivity()
from the Activity's context.Steps to Reproduce:
StackTrace: