How to call Java code Activity from Kotlin compose Activity.
There are a lot of post to the other way(Call Kotlin from Java) but seems it does not apply to my case because it gives (this@MainActivity unresolved reference).
I created Java Activities using the Android Studio templates and they work successfully but I created one manually and that one does not work using the same code to call the other template Activity.
Strangely, instead of giving a runtime error it brings another Activity with a completely different name.
I am providing some code but if you need more to be able to help please advice.
This is the code to call the Activity:
Button(
onClick = {
Log.d("basic activity", "calling")
val intent = Intent(mContext, BasicMainActivity::class.java)
//gdriveCallAct.launch(intent)
mContext.startActivity(intent)
}
) {
Text(text = "Basic Activity")
}
This is calling the manually created Java Activity:
Button(
onClick = {
Log.d("cloud activity", "calling")
val intent = Intent(mContext, CloudMainActivity::class.java)
//gdriveCallAct.launch(intent)
mContext.startActivity(intent)
}
) {
Text(text = "Backup To Cloud")
}
This is the merged Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mastering.houseinventory"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="26"
android:targetSdkVersion="34" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.any" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- Include required permissions for Google Maps API to run. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<queries>
<!-- Needs to be explicitly declared on Android R+ -->
<package android:name="com.google.android.apps.maps" />
</queries>
<permission
android:name="com.mastering.houseinventory.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION"
android:protectionLevel="signature" />
<uses-permission android:name="com.mastering.houseinventory.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION" />
<application
android:allowBackup="true"
android:appComponentFactory="androidx.core.app.CoreComponentFactory"
android:dataExtractionRules="@xml/data_extraction_rules"
android:debuggable="true"
android:extractNativeLibs="false"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:testOnly="true"
android:theme="@style/Theme.HouseInventory"
android:usesCleartextTraffic="true" >
<activity
android:name="com.mastering.houseinventory.MainActivity"
android:exported="true"
android:theme="@style/Theme.HouseInventory"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.mastering.cloud.EmptyMainActivity"
android:exported="false"
android:theme="@style/Theme.HouseInventory" />
<activity
android:name="com.mastering.cloud.CloudMainActivity"
android:exported="false"
android:theme="@style/Theme.HouseInventory" />
<activity
android:name="com.mastering.mylibrary.BasicMainActivity"
android:exported="false"
android:theme="@style/Theme.HouseInventory" />
<activity
android:name="com.mastering.pdfactivity.PdfMainActivity"
android:exported="false"
android:theme="@style/Theme.HouseInventory" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.mastering.houseinventory.provider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/path_provider" />
</provider>
<service
android:name="androidx.room.MultiInstanceInvalidationService"
android:directBootAware="true"
android:exported="false" />
<activity android:name="com.mastering.cloud.ListActivity" />
<activity
android:name="com.karumi.dexter.DexterActivity"
android:theme="@style/Dexter.Internal.Theme.Transparent" />
<activity
android:name="pub.devrel.easypermissions.AppSettingsDialogHolderActivity"
android:exported="false"
android:label=""
android:theme="@style/EasyPermissions.Transparent" /> <!-- Needs to be explicitly declared on P+ -->
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<activity
android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity"
android:excludeFromRecents="true"
android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!--
Service handling Google Sign-In user revocation. For apps that do not integrate with
Google Sign-In, this service will never be started.
-->
<service
android:name="com.google.android.gms.auth.api.signin.RevocationBoundService"
android:exported="true"
android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION"
android:visibleToInstantApps="true" />
<activity
android:name="com.google.android.gms.common.api.GoogleApiActivity"
android:exported="false"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="androidx.compose.ui.tooling.PreviewActivity"
android:exported="true" />
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="com.mastering.houseinventory.androidx-startup"
android:exported="false" >
<meta-data
android:name="androidx.emoji2.text.EmojiCompatInitializer"
android:value="androidx.startup" />
<meta-data
android:name="androidx.lifecycle.ProcessLifecycleInitializer"
android:value="androidx.startup" />
<meta-data
android:name="androidx.profileinstaller.ProfileInstallerInitializer"
android:value="androidx.startup" />
</provider>
<activity
android:name="androidx.activity.ComponentActivity"
android:exported="true" />
<uses-library
android:name="androidx.window.extensions"
android:required="false" />
<uses-library
android:name="androidx.window.sidecar"
android:required="false" />
<receiver
android:name="androidx.profileinstaller.ProfileInstallReceiver"
android:directBootAware="false"
android:enabled="true"
android:exported="true"
android:permission="android.permission.DUMP" >
<intent-filter>
<action android:name="androidx.profileinstaller.action.INSTALL_PROFILE" />
</intent-filter>
<intent-filter>
<action android:name="androidx.profileinstaller.action.SKIP_FILE" />
</intent-filter>
<intent-filter>
<action android:name="androidx.profileinstaller.action.SAVE_PROFILE" />
</intent-filter>
<intent-filter>
<action android:name="androidx.profileinstaller.action.BENCHMARK_OPERATION" />
</intent-filter>
</receiver>
</application>
This is the Log Cat when the failed Activity is called:
2024-06-03 20:27:50.319 545-986 ActivityTaskManager system_server I START u0 {cmp=com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity} with LAUNCH_MULTIPLE from uid 10190 (BAL_ALLOW_VISIBLE_WINDOW) result code=0
2024-06-03 20:27:50.327 29234-29274 WindowManagerShell com.android.systemui V Transition requested: android.os.BinderProxy@2b634e9 TransitionRequestInfo { type = OPEN, triggerTask = TaskInfo{userId=0 taskId=62 displayId=0 isRunning=true baseIntent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.mastering.houseinventory/.MainActivity } baseActivity=ComponentInfo{com.mastering.houseinventory/com.mastering.houseinventory.MainActivity} topActivity=ComponentInfo{com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity} origActivity=null realActivity=ComponentInfo{com.mastering.houseinventory/com.mastering.houseinventory.MainActivity} numActivities=2 lastActiveTime=119544418 supportsMultiWindow=true resizeMode=1 isResizeable=true minWidth=-1 minHeight=-1 defaultMinSize=220 token=WCT{android.window.IWindowContainerToken$Stub$Proxy@e9b56e} topActivityType=1 pictureInPictureParams=null shouldDockBigOverlays=false launchIntoPipHostTaskId=-1 lastParentTaskIdBeforePip=-1 displayCutoutSafeInsets=null topActivityInfo=ActivityInfo{9ddf40f com.mastering.cloud.CloudMainActivity} launchCookies=[] positionInParent=Point(0, 0) parentTaskId=-1 isFocused=true isVisible=true isVisibleRequested=true isSleeping=false topActivityInSizeCompat=false topActivityEligibleForLetterboxEducation= false topActivityLetterboxed= false isFromDoubleTap= false topActivityLetterboxVerticalPosition= -1 topActivityLetterboxHorizontalPosition= -1 topActivityLetterboxWidth=-1 topActivityLetterboxHeight=-1 locusId=null displayAreaFeatureId=1 cameraCompatControlState=hidden}, remoteTransition = null, displayChange = null }
2024-06-03 20:27:50.595 545-2173 CoreBackPreview system_server D Window{84c245d u0 com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@5d0f2a3, mPriority=0, mIsAnimationCallback=false}
2024-06-03 20:27:51.175 545-606 WindowManager system_server V Sent Transition #175 createdAt=06-03 20:27:50.313 via request=TransitionRequestInfo { type = OPEN, triggerTask = TaskInfo{userId=0 taskId=62 displayId=0 isRunning=true baseIntent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.mastering.houseinventory/.MainActivity } baseActivity=ComponentInfo{com.mastering.houseinventory/com.mastering.houseinventory.MainActivity} topActivity=ComponentInfo{com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity} origActivity=null realActivity=ComponentInfo{com.mastering.houseinventory/com.mastering.houseinventory.MainActivity} numActivities=2 lastActiveTime=119544418 supportsMultiWindow=true resizeMode=1 isResizeable=true minWidth=-1 minHeight=-1 defaultMinSize=220 token=WCT{RemoteToken{83f9281 Task{bc505c6 #62 type=standard A=10190:com.mastering.houseinventory}}} topActivityType=1 pictureInPictureParams=null shouldDockBigOverlays=false launchIntoPipHostTaskId=-1 lastParentTaskIdBeforePip=-1 displayCutoutSafeInsets=null topActivityInfo=ActivityInfo{1ad3afb com.mastering.cloud.CloudMainActivity} launchCookies=[] positionInParent=Point(0, 0) parentTaskId=-1 isFocused=true isVisible=true isVisibleRequested=true isSleeping=false topActivityInSizeCompat=false topActivityEligibleForLetterboxEducation= false topActivityLetterboxed= false isFromDoubleTap= false topActivityLetterboxVerticalPosition= -1 topActivityLetterboxHorizontalPosition= -1 topActivityLetterboxWidth=-1 topActivityLetterboxHeight=-1 locusId=null displayAreaFeatureId=1 cameraCompatControlState=hidden}, remoteTransition = null, displayChange = null }
2024-06-03 20:27:51.175 545-606 WindowManager system_server V info={id=175 t=OPEN f=0x0 trk=0 r=[0@Point(0, 0)] c=[{null m=OPEN f=TRANSLUCENT|FILLS_TASK leash=Surface(name=ActivityRecord{d982a91 u0 com.google.android.permissioncontroller/com.android.permissioncontroller.permission.ui.GrantPermissionsActivity)/@0x140aef5 sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=OPEN f=TRANSLUCENT|FILLS_TASK leash=Surface(name=ActivityRecord{a9db746 u0 com.mastering.houseinventory/com.karumi.dexter.DexterActivity)/@0xa4942c sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=OPEN f=FILLS_TASK leash=Surface(name=ActivityRecord{f46892b u0 com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity)/@0xd367fdf sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=TO_BACK f=FILLS_TASK leash=Surface(name=ActivityRecord{d95afa1 u0 com.mastering.houseinventory/.MainActivity)/@0x45cce7f sb=Rect(0, 0 - 1080, 2400) eb=Rect(0, 0 - 1080, 2400) d=0}]}
2024-06-03 20:27:51.175 29234-29274 WindowManagerShell com.android.systemui V onTransitionReady android.os.BinderProxy@2b634e9: {id=175 t=OPEN f=0x0 trk=0 r=[0@Point(0, 0)] c=[{null m=OPEN f=TRANSLUCENT|FILLS_TASK leash=Surface(name=ActivityRecord{d982a91 u0 com.google.android.permissioncontroller/com.android.permissioncontroller.permission.ui.GrantPermissionsActivity)/@0x677ac9c sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=OPEN f=TRANSLUCENT|FILLS_TASK leash=Surface(name=ActivityRecord{a9db746 u0 com.mastering.houseinventory/com.karumi.dexter.DexterActivity)/@0x43436a5 sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=OPEN f=FILLS_TASK leash=Surface(name=ActivityRecord{f46892b u0 com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity)/@0xb7fba7a sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=TO_BACK f=FILLS_TASK leash=Surface(name=ActivityRecord{d95afa1 u0 com.mastering.houseinventory/.MainActivity)/@0x48fc22b sb=Rect(0, 0 - 1080, 2400) eb=Rect(0, 0 - 1080, 2400) d=0}]}
2024-06-03 20:27:51.180 29234-29274 WindowManagerShell com.android.systemui V Transition doesn't have explicit remote, search filters for match for {id=175 t=OPEN f=0x0 trk=0 r=[0@Point(0, 0)] c=[{null m=OPEN f=TRANSLUCENT|FILLS_TASK leash=Surface(name=ActivityRecord{d982a91 u0 com.google.android.permissioncontroller/com.android.permissioncontroller.permission.ui.GrantPermissionsActivity)/@0x677ac9c sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=OPEN f=TRANSLUCENT|FILLS_TASK leash=Surface(name=ActivityRecord{a9db746 u0 com.mastering.houseinventory/com.karumi.dexter.DexterActivity)/@0x43436a5 sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=OPEN f=FILLS_TASK leash=Surface(name=ActivityRecord{f46892b u0 com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity)/@0xb7fba7a sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=TO_BACK f=FILLS_TASK leash=Surface(name=ActivityRecord{d95afa1 u0 com.mastering.houseinventory/.MainActivity)/@0x48fc22b sb=Rect(0, 0 - 1080, 2400) eb=Rect(0, 0 - 1080, 2400) d=0}]}
2024-06-03 20:27:51.188 29234-29274 WindowManagerShell com.android.systemui V start default transition animation, info = {id=175 t=OPEN f=0x0 trk=0 r=[0@Point(0, 0)] c=[{null m=OPEN f=TRANSLUCENT|FILLS_TASK leash=Surface(name=ActivityRecord{d982a91 u0 com.google.android.permissioncontroller/com.android.permissioncontroller.permission.ui.GrantPermissionsActivity)/@0x677ac9c sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=OPEN f=TRANSLUCENT|FILLS_TASK leash=Surface(name=ActivityRecord{a9db746 u0 com.mastering.houseinventory/com.karumi.dexter.DexterActivity)/@0x43436a5 sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=OPEN f=FILLS_TASK leash=Surface(name=ActivityRecord{f46892b u0 com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity)/@0xb7fba7a sb=Rect(0, 0 - 0, 0) eb=Rect(0, 0 - 1080, 2400) d=-1->0 r=-1->0:-1},{null m=TO_BACK f=FILLS_TASK leash=Surface(name=ActivityRecord{d95afa1 u0 com.mastering.houseinventory/.MainActivity)/@0x48fc22b sb=Rect(0, 0 - 1080, 2400) eb=Rect(0, 0 - 1080, 2400) d=0}]}
2024-06-03 20:27:51.456 545-2423 CoreBackPreview system_server D Window{1c2648 u0 com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@db159bf, mPriority=0, mIsAnimationCallback=false}
2024-06-03 20:30:44.302 545-2401 ActivityTaskManager system_server W Force removing ActivityRecord{f46892b u0 com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity t62 f}}: app died, no saved state
2024-06-03 20:30:44.432 545-610 WindowManager system_server W Failed to deliver inset control state change to w=Window{84c245d u0 com.mastering.houseinventory/com.mastering.cloud.CloudMainActivity}
android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(BinderProxy.java:584)
at android.view.IWindow$Stub$Proxy.insetsControlChanged(IWindow.java:479)
at com.android.server.wm.WindowState.notifyInsetsControlChanged(WindowState.java:3802)
at com.android.server.wm.InsetsStateController.lambda$notifyPendingInsetsControlChanged$3(InsetsStateController.java:343)
at com.android.server.wm.InsetsStateController.$r8$lambda$8yykPRG1GyNq_J17QvL9d5xANMc(InsetsStateController.java:0)
at com.android.server.wm.InsetsStateController$$ExternalSyntheticLambda2.run(R8$$SyntheticClass:0)
at com.android.server.wm.WindowAnimator.executeAfterPrepareSurfacesRunnables(WindowAnimator.java:294)
at com.android.server.wm.WindowAnimator.animate(WindowAnimator.java:202)
at com.android.server.wm.WindowAnimator.lambda$new$1(WindowAnimator.java:99)
at com.android.server.wm.WindowAnimator.$r8$lambda$aHNu1uhcqxihX5NZc4McDDQPAyw(WindowAnimator.java:0)
at com.android.server.wm.WindowAnimator$$ExternalSyntheticLambda1.doFrame(R8$$SyntheticClass:0)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1337)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1348)
at android.view.Choreographer.doCallbacks(Choreographer.java:952)
at android.view.Choreographer.doFrame(Choreographer.java:878)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1322)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.os.HandlerThread.run(HandlerThread.java:67)
at com.android.server.ServiceThread.run(ServiceThread.java:46)