android-activity 相关问题

有关在Android中创建或管理活动的问题。在Android应用程序中,Activity是一个组件,它提供允许用户执行某些操作的用户界面。简单的例子包括:拨打电话,拍照,发送电子邮件或查看地图。

在 Flutter 应用程序中使用单独的 FlutterFragmentActivity

我一直在努力解决一个问题。我们在 Flutter 项目中使用以下插件: https://pub.dev/packages/truecaller_sdk https://pub.dev/packages/flutter_branch_sdk 问题在这里我...

回答 1 投票 0

有没有办法阻止USB设备触发Android活动的暂停/恢复周期?

MainActivity的AndroidManifest.xml中如下: 以下内容位于 MainActivity 的 AndroidManifest.xml 中: <activity android:name=".MainActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:directBootAware="true" android:exported="true" android:icon="@mipmap/ic_launcher_round" android:launchMode="singleInstance" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> </intent-filter> <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/usb_device_filter" /> </activity> 如果我第一次插入USB设备A、B和C,操作系统会提示我选择应用程序。这正是应该的。当我拔掉所有插头,然后重新插回后,MainActivity 暂停并恢复三次(即暂停和恢复,在不到一秒的时间里再次暂停和恢复,然后在不到一秒的时间里暂停和恢复最后一次)。该应用程序始终位于前台。 这不是一个大问题。这是可以管理的。我很好奇,当应用程序已经在前台时,是否有一种方法可以避免这种无用的暂停/恢复循环。 潜在的解决方案: 由于无法测试,以下是发生这种情况的一个可能原因。 您正在使用 launchMode 作为“singleInstance”运行。重新插回三个 USB 设备时遇到的三个暂停-恢复周期可能是三个重新启动周期。 尝试设置 android:launchMode="singleTop" 文档单页顶部 如果目标任务顶部已存在 Activity 的实例,系统将通过调用其 onNewIntent() 方法将 Intent 路由到该实例,而不是创建 Activity 的新实例。 我的推理是 singleTop 可能会专门将 newIntent 路由到已经运行的实例。根据我们现有的信息,这是一种可能的解决方案。

回答 1 投票 0

更多活动还是1-2个活动和多个片段? Jetpack compose 或 XML 或两者兼而有之?

我正在构建一个简单的应用程序,它基本上是从回收器视图中进行文本输入和多项选择输入,从 API 中提取。然后将表单答案导出为 pdf,将其上传到数据库,然后

回答 1 投票 0

Android 中如何通过通知检查 Activity 是否已启动?

我正在制作一个Android应用程序。我有问题,即我的 MainActivity 可以通过 3 种方式创建: 标准应用程序启动 来自服务 并从通知中单击。 我如何检查它何时开始

回答 2 投票 0

Kotlin Android 启动新 Activity

我想在 Android 上启动另一个 Activity,但收到此错误: 请指定构造函数调用;分类器“Page2”没有伴随对象 实例化 Intent 类后...

回答 20 投票 0

如何使用 FAB 按钮从 MainActivity 导航到(第二个)片段?

我正在使用基本活动模板开发一个 Android 项目。 Android studio 提供了MainActivity 和两个fragment(以及一个额外的contents_main 布局)。 MainActivity 布局有一个

回答 1 投票 0

通过 RunOnUIThread 更改 MainActivity 上的按钮颜色会崩溃

我得到了 kotlin.UninitializedPropertyAccessException:lateinit 属性 BTNStatus05 尚未初始化 当我尝试设置 ButtonColor 时。 这个想法是改变按钮上的按钮颜色等,

回答 1 投票 0

如何为每个片段应用不同的工具栏(操作栏)布局?

我正在应用单活动架构,我想通过工具栏使用顶部固定栏。 在我的项目中,工具栏的形式因片段而异,并且形式我...

回答 1 投票 0

Android MainActivity 的 onCreate() 在安装后首次启动时被调用两次

问题: 我遇到一个不寻常的问题,即我的应用程序启动器活动 (MainActivity) 的 onCreate() 方法被调用两次,但仅当我在

回答 2 投票 0

如何将登录屏幕放置在片段内?

我正在尝试构建一个Android应用程序,其中有一个导航抽屉,其中有5个不同的选项。 对于第一个选项,我正在尝试实现登录屏幕。然而我却无法得到...

回答 1 投票 0

避免在活动中检测到 NFC 标签

我有一个要求,其中我的应用程序处理 NFC。 我已在清单文件中声明了 NFC。 我的应用程序需要处理 NFC。 我已在清单文件中声明了 NFC。 <uses-feature android:name="android.hardware.nfc" android:required="true"/> 我的问题是:是否可以在特定活动中禁用 NFC 标签检测? 例如,我有 10 个活动,我不希望第 5 个活动检测到 NFC。这可能吗? 您无法真正阻止设备检测 NFC 标签。但是,您可以做的是将您的 Activity 设置为接收(然后忽略)所有 NFC 发现事件。 为此,您需要使用 NfcAdapter 的 enableForegroundDispatch() 方法向 NFC 前台调度系统注册您的活动。这使您当前的活动在接收 NFC 事件时优先于所有其他意图过滤器。请参阅高级 NFC:使用 NFC 前台调度系统了解如何进行此注册。 一旦您注册了前台调度系统,您的 Activity 将在其 onNewIntent() 方法中接收所有 NFC 意图(或作为待处理的意图结果,具体取决于您的注册方式)。在那里,您可以简单地忽略这些事件。 当你的 Activity 被销毁或暂停时,你只需调用这个即可 nfcAdapter.disableForegroundDispatch(getActivity());

回答 2 投票 0

致命异常:java.lang.IllegalStateException 从 INITIALIZED 开始没有事件发生

不确定我在应用程序中更改了什么,但在发布后我突然得到了这个无法追踪的堆栈跟踪(我更新了一些依赖项,但不确定是什么导致了它,因为我无法

回答 7 投票 0

将 Activity 更改为 Fragment

我使用 Activity 启动了一个项目,但是现在我需要它成为一个片段,因为我想使用底部导航栏。我该怎么做呢?我是 Android 开发新手,但我陷入了困境。 ...

回答 1 投票 0

Glance 小部件 actionStartActivity 无法正常工作

我正在尝试实现一个概览小部件并在单击按钮时启动一个活动。但它似乎对我来说不能正常工作。这是我的代码: DistributionDateView(上下文,

回答 2 投票 0

ActivityInjector 的活动错误获取生命周期异常

我的应用程序在启动时崩溃,然后我收到此错误,这种情况很少发生。 [ 11-22 11:27:13.287 26135:26135 E/ActivityInjector ] 获取生命周期异常 java.lang.ClassCastException: android.os.BinderPr...

回答 3 投票 0

如何解决无法访问“androidx.core.app.ComponentActivity”的错误

几天前我正在做一个项目,该项目已保存并关闭,结果今天打开它时,MainActivity 中出现错误。 错误:无法访问“androidx.core.app.ComponentActivity”

回答 2 投票 0

如何通过 Activity 中发生的点击事件关闭 Fragment 中的会话

我继承了一个视频播放应用程序,我需要向其中添加分析。在我的片段中,我创建了分析对象,然后该对象侦听并报告事件和数据。如果用户点击...

回答 1 投票 0

Android、Java:Android 资源链接失败 -\...\debug\AndroidManifest.xml:15:错误:在 <activity><manifest> 中找到意外元素

在我的 AndroidManifest.xml 中我编写了以下代码: 在我的 AndroidManifest.xml 中我写了这段代码: <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="example.on.myapp12" tools:ignore="ExtraText"> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/> <application android:requestLegacyExternalStorage="true" android:allowBackup="true" ></application> <activity android:name=".MainActivity" android:label="myapp12"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </manifest> 应用程序运行后我看到: Android资源链接失败 C:\Users\miroslav\AndroidStudioProjects\myapp12 pp uild\intermediates\packaged_manifests\debug\AndroidManifest.xml:15:错误:在 . 中找到意外元素 我真的不知道出了什么问题...... 我认为您忘记将活动标签放入应用程序标签中 在应用程序标签内添加活动 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="example.on.myapp12" tools:ignore="ExtraText"> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/> <application android:requestLegacyExternalStorage="true" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="false" android:theme="@style/Theme"> <activity android:name=".MainActivity" android:exported="true" android:label="myapp12"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>

回答 1 投票 0

无法查看 kotlin 中的其他活动

它移至活动,但我得到一个空白页面 MainActivit.kt 这是我用来移动的方块 绑定.fab2.setOnClickListener { val 意图 = Intent(this, InfoActivity::class.java) ...

回答 1 投票 0

Android Kotlin:无法使用 registerforactivityresult

迁移下一个 Java 类后: 公共类 ImportExportActivity 扩展 BaseActivity { 私有字符串文件名; 私有静态意图oData; 私人 ActivityResultLauncher 迁移下一个 Java 类后: public class ImportExportActivity extends BaseActivity { private String filename; private static Intent oData; private ActivityResultLauncher<Intent> activityResultLauncher; private ActivityImportexportBinding binding; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setImportDataActivityResultHandler(); } @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) private void setImportDataActivityResultHandler(){ activityResultLauncher = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), result -> { if (result.getResultCode() == Activity.RESULT_OK) { Intent data = result.getData(); if (data != null) { oData = data; boolean hasPermission = TMPermission.verifyStorageReadPermissions((Activity)AppSettings.getContext()); appSettings.setRequestPermissionSource(RequestPermissionSource.IMPORTDATA); if (hasPermission) { String strResult = TMImport.importData(data); TMToast toast = new TMToast(AppSettings.getContext()); toast.show(strResult, Toast.LENGTH_LONG); } } } }); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if(appSettings.getRequestPermissionSource() .equals(RequestPermissionSource.IMPORTDATA)){ if (TMPermission.hasReadPermission()) { String strResult = TMImport.importData(oData); TMToast toast = new TMToast(this); toast.show(strResult, Toast.LENGTH_LONG); } } } public void setActivityLayout() { super.setActivityLayout(); setButtonsAppearance(); } public void setContentView() { binding = DataBindingUtil.setContentView(this, R.layout.activity_importexport); } public void setActivityBackground(){ binding.llImportExportMain.setBackgroundColor(Color.parseColor( appSettings.mainLayoutBackgroundColor )); } public void createActionBar() { String activityTitle = TMLocale.getStringResourceByName("activityrecords_textview_importexport").toUpperCase(); TMAppearance.createActionBar(this, activityTitle); } public void setFooterMenu() { FootermenuBinding footerBinding = binding.footermenu; TMFooter.footerBinding = new WeakReference<>(footerBinding); TMFooter.activity = new WeakReference<>(this); TMFooter.dialog = new WeakReference<>(dialog); TMFooter.setFooterMenu(); } private void setButtonsAppearance() { configureButton(binding.btnImport); configureButton(binding.btnExport); setButtonClickListener(binding.cvImport, Enum.Action.IMPORT); setButtonClickListener(binding.cvExport, Enum.Action.EXPORT); } @SuppressLint("ClickableViewAccessibility") private void setButtonClickListener(CardView button, String target) { button.setOnTouchListener((v, event) -> { if (event.getAction() == MotionEvent.ACTION_DOWN) { TMSound.playButtonSound(this); setButtonStyle_Pressed(button); } else { if (event.getAction() == MotionEvent.ACTION_UP) { setButtonStyle_Released(button); switch (target) { case (Enum.Action.IMPORT): selectFile(); break; case (Enum.Action.EXPORT): onTouchExport(); break; } } } return true; }); } private void onTouchExport() { //check if there is data to export TMSession us = new TMSession(); User user = us.getUserSession(); List<RecordDTO> records = UserService.getRecords(user.getId(), ""); if (records.size()>0){ exportData(); }else{ String strError = TMLocale.getStringResourceByName("activityimportexport_nodatatoexport"); TMToast toast = new TMToast(this); toast.show(strError, Toast.LENGTH_SHORT); } } private void configureButton(TextView button) { int dpButtonHeight = TMActivity.getButtonsHeight(3); // TMScreen.dp2px(height); button.setHeight(dpButtonHeight); button.setTextSize(TMAppearance.getPrefsByScreenDensity()[3]); } /** * Imports records data from file into records table */ private void selectFile() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); activityResultLauncher.launch(intent); } private void exportData() { String recordsData = TMExport.getRecordsData(); try { filename = getFilename(); File filelocation = TMFile.writeFile(this, filename, recordsData); sendExportFileTo(filelocation); } catch (IOException e) { TMToast toast = new TMToast(this); toast.show(e.getMessage(), Toast.LENGTH_SHORT); ExceptionHandler.logException(e); } } private String getFilename() { SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.ENGLISH); Date now = new Date(); return "testme_exportfile_" + formatter.format(now) + ".txt"; } private void sendExportFileTo(File attachment) { Uri uri = FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", attachment); Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); i.putExtra(Intent.EXTRA_EMAIL, new String[] { "" }); String subject = TMLocale.getStringResourceByName("importexport_exporttomail_subject") + " " + filename; String body = TMLocale.getStringResourceByName("importexport_exporttomail_body"); i.putExtra(Intent.EXTRA_SUBJECT, subject); i.putExtra(Intent.EXTRA_TEXT, body); i.putExtra(Intent.EXTRA_STREAM, uri); try { this.startActivity(Intent.createChooser(i, "Send mail...")); } catch (android.content.ActivityNotFoundException e) { Toast.makeText(this, TMLocale.getStringResourceByName("importexport_exporttomail_noemailclients"), Toast.LENGTH_SHORT) .show(); ExceptionHandler.logException(e); } } } 对于 Kotlin,我以 结束。下一堂课: class ImportExportActivity : BaseActivity() { private var filename: String? = null private var activityResultLauncher: ActivityResultLauncher<Intent>? = null private var binding: ActivityImportexportBinding? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setImportDataActivityResultHandler() } private fun setImportDataActivityResultHandler() { activityResultLauncher = registerForActivityResult<Intent, ActivityResult>( StartActivityForResult(), ActivityResultCallback { result: ActivityResult -> if (result.resultCode == Activity.RESULT_OK) { val data = result.data if (data != null) { oData = data val hasPermission = TMPermission.verifyStorageReadPermissions(AppSettings.getContext() as Activity) appSettings.requestPermissionSource = RequestPermissionSource.IMPORTDATA if (hasPermission) { val strResult = TMImport.importData(data) val toast = TMToast(AppSettings.getContext()) toast.show(strResult, Toast.LENGTH_LONG) } } } }) } override fun onRequestPermissionsResult( requestCode: Int, permissions: Array<String>, grantResults: IntArray ) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) if (appSettings.requestPermissionSource == RequestPermissionSource.IMPORTDATA ) { if (TMPermission.hasReadPermission()) { val strResult = TMImport.importData(oData) val toast = TMToast(this) toast.show(strResult, Toast.LENGTH_LONG) } } } override fun setActivityLayout() { super.setActivityLayout() setButtonsAppearance() } override fun setContentView() { binding = DataBindingUtil.setContentView(this, R.layout.activity_importexport) } override fun setActivityBackground() { binding!!.llImportExportMain.setBackgroundColor( Color.parseColor( appSettings.mainLayoutBackgroundColor ) ) } override fun createActionBar() { val activityTitle = TMLocale.getStringResourceByName("activityrecords_textview_importexport").uppercase( Locale.getDefault() ) createActionBar(this, activityTitle) } override fun setFooterMenu() { val footerBinding = binding!!.footermenu TMFooter.footerBinding = WeakReference(footerBinding) TMFooter.activity = WeakReference(this) TMFooter.dialog = WeakReference(dialog) TMFooter.setFooterMenu() } private fun setButtonsAppearance() { configureButton(binding!!.btnImport) configureButton(binding!!.btnExport) setButtonClickListener(binding!!.cvImport, Enum.Action.IMPORT) setButtonClickListener(binding!!.cvExport, Enum.Action.EXPORT) } @SuppressLint("ClickableViewAccessibility") private fun setButtonClickListener(button: CardView, target: String) { button.setOnTouchListener { v: View?, event: MotionEvent -> if (event.action == MotionEvent.ACTION_DOWN) { TMSound.playButtonSound(this) setButtonStyle_Pressed(button) } else { if (event.action == MotionEvent.ACTION_UP) { setButtonStyle_Released(button) when (target) { Enum.Action.IMPORT -> selectFile() Enum.Action.EXPORT -> onTouchExport() } } } true } } private fun onTouchExport() { //check if there is data to export val us = TMSession() val user = us.userSession val records = UserService.getRecords(user.id, "") if (records.size > 0) { exportData() } else { val strError = TMLocale.getStringResourceByName("activityimportexport_nodatatoexport") val toast = TMToast(this) toast.show(strError, Toast.LENGTH_SHORT) } } private fun configureButton(button: TextView) { val dpButtonHeight = getButtonsHeight(3) // TMScreen.dp2px(height); button.height = dpButtonHeight button.textSize = prefsByScreenDensity[3].toFloat() } /** * Imports records data from file into records table */ private fun selectFile() { val intent = Intent(Intent.ACTION_GET_CONTENT) intent.type = "*/*" intent.addCategory(Intent.CATEGORY_OPENABLE) activityResultLauncher!!.launch(intent) } private fun exportData() { val recordsData = TMExport.getRecordsData() try { filename = getFilename() val filelocation = TMFile.writeFile(this, filename, recordsData) sendExportFileTo(filelocation) } catch (e: IOException) { val toast = TMToast(this) toast.show(e.message, Toast.LENGTH_SHORT) ExceptionHandler.logException(e) } } private fun getFilename(): String { val formatter = SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.ENGLISH) val now = Date() return "testme_exportfile_" + formatter.format(now) + ".txt" } private fun sendExportFileTo(attachment: File) { val uri = FileProvider.getUriForFile( this, this.applicationContext.packageName + ".provider", attachment ) val i = Intent(Intent.ACTION_SEND) i.type = "text/plain" i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) i.putExtra(Intent.EXTRA_EMAIL, arrayOf("")) val subject = TMLocale.getStringResourceByName("importexport_exporttomail_subject") + " " + filename val body = TMLocale.getStringResourceByName("importexport_exporttomail_body") i.putExtra(Intent.EXTRA_SUBJECT, subject) i.putExtra(Intent.EXTRA_TEXT, body) i.putExtra(Intent.EXTRA_STREAM, uri) try { this.startActivity(Intent.createChooser(i, "Send mail...")) } catch (e: ActivityNotFoundException) { Toast.makeText( this, TMLocale.getStringResourceByName("importexport_exporttomail_noemailclients"), Toast.LENGTH_SHORT ) .show() ExceptionHandler.logException(e) } } companion object { private var oData: Intent? = null } } 并且“registerForActivityResult”不再被编译器识别。 正如我在这里读到的:Android ActivityResult API 未解决的参考错误 registerForActivityResult 解决方案通过在 build.gradle 中导入接下来的两个包: api 'androidx.activity:activity-ktx:1.6.0-alpha05' api 'androidx.fragment:fragment-ktx:1.5.0-rc01' 然后让你的 Activity 扩展 ComponentActivity。 好吧,我尝试了这个解决方案并且它有效,现在可以识别“registerforactivityresult”,但是我无法从ComponentActivity继承,因为我所有的活动都扩展了BaseActivity,并且BaseActivity扩展了AppCompatActivity,所以我无法扩展ComponentActivity 在 BaseActivity 中也可以。 这么说,鉴于我的场景,我陷入了困境,不知道如何在 Kotlin 中使用 registerforactivityresult。 编辑1: 这是我的 build.gradle 支持部分: api 'androidx.legacy:legacy-support-v4:1.0.0' api 'androidx.appcompat:appcompat:1.4.2' api 'androidx.cardview:cardview:1.0.0' api 'androidx.recyclerview:recyclerview:1.2.1' api 'androidx.preference:preference-ktx:1.2.0' 编辑2: 不确定这是否是最终的解决方案,但在 AppCompatActivity 类中用 ComponentActivity 替换 BaseActivity 解决了编译问题。 编辑3: 用AppCompatActivity改变ComponentActivity最终更多的是一种幻想而不是解决方案。如果我扩展 ComponentActivity,registerforactivityresult 开始工作,但 FragmentActivities 停止编译,因为要使用SectionsPagerAdapter,我的类需要扩展 FragmentActivity。这就像一个恶性循环。 编辑4: 我完整的build.gradle: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 32 def code Properties versionProps = new Properties() def versionPropsFile = file('version.properties') if (versionPropsFile.exists()) versionProps.load(new FileInputStream(versionPropsFile)) code = (versionProps['VERSION_CODE'] ?: "0").toInteger()+ 1 packagingOptions { resources { pickFirsts += ['META-INF/LICENSE.txt'] excludes += ['META-INF/NOTICE.md', 'META-INF/LICENSE.md', 'META-INF/INDEX.LIST', 'META-INF/DEPENDENCIES', 'META-INF/io.netty.versions.properties'] } } versionProps['VERSION_CODE'] = code.toString() versionProps.store(versionPropsFile.newWriter(), null) defaultConfig { applicationId 'com.xxx.xxx' minSdkVersion 26 targetSdkVersion 32 multiDexEnabled true versionCode code versionName "3.0." + code compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } bundle { density { // Different APKs are generated for devices with different screen densities; true by default. enableSplit true } abi { // Different APKs are generated for devices with different CPU architectures; true by default. enableSplit true } language { // This is disabled so that the App Bundle does NOT split the APK for each language. // We're gonna use the same APK for all languages. enableSplit false } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' applicationVariants.all { variant -> variant.outputs.all { output -> project.ext { appName = 'xxx' } def newName = 'xxx.apk' outputFileName = new File("./build/", newName) } } } debug { } } productFlavors { } dataBinding{ enabled = true } lint { abortOnError false checkReleaseBuilds false } namespace 'com.xxx.xxx' } dependencies { api files('libs/achartengine-1.2.0.jar') api 'com.facebook.android:facebook-android-sdk:14.0.0' //mail API 16 implementation 'com.sun.mail:android-mail:1.6.7' implementation 'com.sun.mail:android-activation:1.6.7' //apache commons text implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9' //Youtube player api 'com.thefinestartist:ytpa:1.2.1' //Font Selector List Preference //api 'com.vanniktech:vntfontlistpreference:1.0.0' //Rate my app api 'com.github.hotchemi:android-rate:1.0.1' //Support api 'androidx.legacy:legacy-support-v4:1.0.0' api 'androidx.appcompat:appcompat:1.4.2' api 'androidx.cardview:cardview:1.0.0' api 'androidx.recyclerview:recyclerview:1.2.1' api 'androidx.preference:preference-ktx:1.2.0' //Annotation api 'androidx.annotation:annotation:1.4.0' //AlertDialog api 'com.github.d-max:spots-dialog:1.1@aar' //glide animated gifs api 'com.github.bumptech.glide:glide:4.13.2' annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2' //circular score api 'com.wssholmes.stark:circular-score:0.1.1' api 'com.google.android.material:material:1.6.1' api 'com.github.mejdi14:Flat-Dialog-Android:1.0.5' //picasso api 'com.squareup.picasso:picasso:2.71828' //Gson implementation 'com.google.code.gson:gson:2.9.0' //Stream api 'com.annimon:stream:1.2.2' api 'androidx.activity:activity-ktx:1.6.0-alpha05' api 'androidx.activity:activity-ktx:1.4.0' api 'androidx.fragment:fragment-ktx:1.5.0-rc01' /*implementation 'jp.wasabeef:picasso-transformations:2.4.0'*/ //zoom //implementation 'com.alexvasilkov:gesture-views:2.8.2' //implementation 'com.otaliastudios:zoomlayout:1.8.0' //Multidex implementation "androidx.multidex:multidex:2.0.1" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation project(':Global') implementation project(':DTO') implementation project(':Common') implementation project(':Background') implementation project(':Services') } 奇怪的是,即使出现 lint 错误,应用程序也可以正常构建,但由于我正在迁移过程中,还无法测试 registerForActivityResult,但我想它很可能无法工作。 编辑5: 在下一个 Google 页面中: https://developer.android.com/jetpack/androidx/releases/activity 说: "The registerForActivityResult() API has been renamed to rememberLauncherForActivityResult()..." 但同样的情况也发生在rememberLauncherForActivityResult上,它没有找到。我完全被困住了。 编辑6: 据我所读,也许这只是一个“视觉”问题,比如说 Android Studio IDE 问题,因为应用程序构建得很好(不过,我还没有测试过 registerForActivityResult),但无论如何我厌倦了谷歌。 随着时间的推移,软件包每次都会更快地被标记为过时,而令人惊奇的是“替代”并不总是有效。 目前,我将保留我的“registerForActivityResult”问题(因为我别无选择),但老实说,在我看来,Google 不鼓励我们开发者保持我们的应用程序最新。 我最终为此函数创建了一个扩展: fun <I, O> Activity.registerForActivityResult( contract: ActivityResultContract<I, O>, callback: ActivityResultCallback<O> ) = (this as ComponentActivity).registerForActivityResult(contract, callback) AndroidStudio 似乎存在一个未解决的错误: 错误:尽管具有所需的依赖项,但无法在大型项目上找到 registerForActivityResult

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.