小编Ste*_*ail的帖子

使用 Jetpack Compose 的深度链接导航到可组合项

当用户在我们的应用程序中进入地理围栏时,我们会向他们显示有关该区域的优惠通知,单击该通知后,应将他们引导至名为 的特定可组合屏幕SingleNotification。我已经遵循了谷歌的代码实验室及其文档,但我还没有设法使到特定屏幕的导航正常工作。现在,单击通知或运行命令adb shell am start -d \xe2\x80\x9ceway://station_offers/date_str/www.test.com/TITLE/CONTENT\xe2\x80\x9d -a android.intent.action.VIEW,只需打开应用程序即可。

\n

该活动在清单中声明如下:

\n
    <activity\n        android:name=".MainActivity"\n        android:exported="true"\n        android:label="@string/app_name"\n        android:screenOrientation="portrait">\n        <intent-filter>\n            <action android:name="android.intent.action.MAIN" />\n\n            <category android:name="android.intent.category.LAUNCHER" />\n\n            <category android:name="android.intent.category.DEFAULT" />\n            <category android:name="android.intent.category.BROWSABLE" />\n        </intent-filter>\n\n        <intent-filter>\n            <action android:name="android.intent.action.VIEW" />\n\n            <category android:name="android.intent.category.DEFAULT" />\n            <category android:name="android.intent.category.BROWSABLE" />\n\n            <data\n                android:host="station_offers"\n                android:scheme="eway" />\n        </intent-filter>\n    </activity>\n
Run Code Online (Sandbox Code Playgroud)\n

我们的 MainNavController 类包含 NavHost,而 NavHost 又包含各种 NavGraph。我只包含了下面的相关图表:

\n
        NavHost(\n            navController = navController,\n            startDestination = NavigationGraphs.SPLASH_SCREEN.route\n        ) {\n....\n            notificationsNavigation()\n....    \n    }\n
Run Code Online (Sandbox Code Playgroud)\n

通知导航图定义如下:

\n
fun …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-deep-link android-jetpack-compose

11
推荐指数
2
解决办法
7350
查看次数

首选项库导致 E/libc &amp; E/Pref 错误

我正在使用 MVVM 和改造构建一个天气应用程序,我最近添加了一个 PreferencesFragmentCompat 子类来使用首选项库实现一些用户设置。这样做之后,我的应用程序将无法运行,并且我不断收到以下几行错误:

2020-04-08 00:54:12.346 18079-18079/? E/de.flogaweathe: Unknown bits set in runtime_flags: 0x8000
2020-04-08 00:54:12.410 18079-18079/com.nesoinode.flogaweather E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: Fail to get file list com.nesoinode.flogaweather
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: Fail to get file list oat
2020-04-08 00:54:12.422 18079-18110/com.nesoinode.flogaweather E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
Run Code Online (Sandbox Code Playgroud)

我不知道这些是什么,我在堆栈或谷歌上找不到任何具体的答案。没有迹象表明是什么导致了错误,所以我不知道我是否做错了什么是图书馆的问题。有任何想法吗?

这是我从 xml 资源文件添加首选项的 …

logcat sharedpreferences android-studio preferencefragment

8
推荐指数
1
解决办法
7157
查看次数

房间实体的数据已正确存储,但检索为空

我正在尝试做什么

当我的应用程序启动时,我使用一个片段,该片段使用AutoCompleteTextViewPlaces SDKPlace在用户做出选择时获取对象。发生这种情况时,我通过调用将选定的地点(作为 WeatherLocation 实体)存储在我的 Room 数据库中repository.storeWeatherLocation(context,placeId),然后根据需要再次获取天气详细信息。

发生了什么

正在suspend fun storeWeatherLocationAsync调用fetchCurrentWeather()& ,fetchWeeklyWeather()因为从我能够记录的内容来看,previousLocation尽管数据库检查器显示旧的天气位置数据已经存在,但该变量为空。

崩溃详情

我的应用程序崩溃,表明我的 LocationProvidergetCustomLocationLat()返回 null(发生在fetchCurrentWeather())。问题是用户选择的位置已成功存储在我的 Room 数据库中(使用 Database Inspector 检查),那么这个函数如何返回 null?

更新

使用调试器和 logcat 进行更多测试后,我发现WeatherLocation应用程序运行时数据会保存在 Room 中。一旦它崩溃并且我重新打开它,该数据再次为空。我在这里缺少什么?我是否以某种方式删除了以前的数据?我实际上没有在房间中正确缓存它吗?

数据库类:

@Database(
    entities = [CurrentWeatherEntry::class,WeekDayWeatherEntry::class,WeatherLocation::class],
    version = 16
)
abstract class ForecastDatabase : RoomDatabase() {
    abstract fun currentWeatherDao() : CurrentWeatherDao
    abstract fun weekDayWeatherDao() : WeekDayWeatherDao
    abstract fun weatherLocationDao() : WeatherLocationDao

    // …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-room android-livedata

8
推荐指数
1
解决办法
5503
查看次数

使用 Glide 在 RecyclerView 中加载图像时 UI 滞后且不稳定

我有一个 RecyclerView,它使用 Glide 从 URL 加载图像。现在,使用分页从 Firebase 检索 URL,如下所示。问题是,当 MainActivity(包含以下代码和 recyclerview)首次初始化时,UI 中存在很大的延迟(滚动非常缓慢且断断续续,选项菜单需要 3 秒才能打开等),并且图像需要一段时间才能显示出来。加载时。当我向下滚动并到达第一页数据的 RecyclerView 末尾后,OnScrollListener 被触发,我开始从新查询加载新数据。我已经尽力根据我发表的另一篇文章中的用户建议来优化 Glide 的功能,并且我也将其设置adapter.setHasFixedSize为 true,但运气不佳。知道这里发生了什么吗?尽管查询是异步的,但我是否以某种方式挂起 UI 线程?

编辑 :Glide 是否会由于必须将多个图像加载到回收器视图的 imageViews 中而导致主线程上的滞后?如果是这样,我能做什么来应对呢?

以下是我处理从 Firebase 获取的数据的分页并通知适配器的方法:

class MainActivity : AppCompatActivity() {

private val TAG: String = MainActivity::class.java.simpleName // Tag used for debugging
private var queryLimit : Long = 50 // how many documents should the query request from firebase
private lateinit var iconsRCV : RecyclerView // card icons recycler view
private lateinit var lastVisible:DocumentSnapshot …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-glide google-cloud-firestore

7
推荐指数
1
解决办法
1万
查看次数

水平滚动文本性能问题

我的应用程序包含一些textViews应该水平滚动的应用程序.当我layout第一次加载时,但是在点击a button加载另一个layout然后再重新点击它button以加载第一个layout 那些textViews在"大"延迟(如20秒+)之后开始滚动时,这种方法就有效.我试图用等等找出这个问题的根源Layout Inspector,Hierarchy Viewer但没有运气.

UPDATE: I noticed something strange today.When i go from the 1st layout to the 2nd one and vice versa, although the TextViews stop scrolling, if i close and re-open the phone's screen, the scrolling works like a charm. This seems totally strange to me, do you know what's causing this and why?

CardViewActivity.java:

public class CardViewActivity …
Run Code Online (Sandbox Code Playgroud)

java xml android textview android-layout

6
推荐指数
1
解决办法
241
查看次数

在 Compose 中使用 DeepLinks 会导致无法向后导航

我有一个 FirebaseMessagingService 子类,它接收通知负载,然后使用以下 PendingIntent 创建推送通知:

        TaskStackBuilder.create(this).run {
            addNextIntentWithParentStack(
                Intent(
                    Intent.ACTION_VIEW,
                    "eway://traversals_monthly_bill_details".toUri()
                )
            )
            getPendingIntent(2345, PendingIntent.FLAG_UPDATE_CURRENT)
        }
Run Code Online (Sandbox Code Playgroud)

以下是导航的各个嵌套图的可组合项:

    composable(Screens.INTERMEDIATE_MONTHLY_BILLINGS.navRoute,
        deepLinks =
        listOf(
            navDeepLink {
                uriPattern =
                    "eway://traversals_monthly_bill_details"
            }
        )) {
        IntermediateMonthlyBillings({ statements ->
            val lastIndex = statements.lastIndex
            val gson = GsonBuilder().create()
            val statementsByYearJson = gson.toJson(statements)
            navController.navigate("${Screens.MONTHLY_BILLINGS}/$statementsByYearJson/$lastIndex")
        })
    }
    composable("${Screens.MONTHLY_BILLINGS.navRoute}/{statementsByYear}/{initialIndex}",
        arguments = listOf(
            navArgument("statementsByYear") {},
            navArgument("initialIndex") {
                type = NavType.IntType
            }
        )
    ) {
        val gson = GsonBuilder().create()
        val statementsByYear = gson.fromJson(
            it.arguments?.getString("statementsByYear"),
            AllStatementsByYear::class.java
        )
        MonthlyBillings(statementsByYear, it.arguments?.getInt("initialIndex")!!)
        updateCurrentScreen(Screens.MONTHLY_BILLINGS)
    }
Run Code Online (Sandbox Code Playgroud)

这是中间屏幕:

@Composable
fun …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-deep-link android-jetpack-compose

6
推荐指数
1
解决办法
1095
查看次数

Systrace输出错误

我在我的android studio项目上运行systrace以找到一些性能错误但是在跟踪过程结束后,我得到以下错误,如果我在chrome中打开trace.html输出文件,则跟踪视图为空:

Starting tracing (10 seconds)
Tracing completed. Collecting output...
Exception in thread Thread-13:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:\Users\Steli\AppData\Local\Android\sdk\platform-tools\systrace\catapult\systrace\systrace\tracing_agents\atrace_agent.py", line 194, in _collect_and_preprocess
    self._trace_data = self._preprocess_trace_data(trace_data)
  File "C:\Users\Steli\AppData\Local\Android\sdk\platform-tools\systrace\catapult\systrace\systrace\tracing_agents\atrace_agent.py", line 272, in _preprocess_trace_data
    trace_data = strip_and_decompress_trace(trace_data)
  File "C:\Users\Steli\AppData\Local\Android\sdk\platform-tools\systrace\catapult\systrace\systrace\tracing_agents\atrace_agent.py", line 332, in strip_and_decompress_trace
    trace_data = zlib.decompress(trace_data)
error: Error -5 while decompressing data: incomplete or truncated stream

Outputting Systrace results...
Tracing complete, writing results
Traceback (most …
Run Code Online (Sandbox Code Playgroud)

html android google-chrome systrace android-studio

5
推荐指数
1
解决办法
998
查看次数

观察者内部协程内部的地理编码未运行

在我的片段中,我有一个bindUI()方法,其中包含我正在观察的一些 liveData,并且在 lambda 内部,我想使用该值location(包含纬度和经度值)来根据它包含的坐标检索地址列表。有人告诉我地理编码应该在协程内部完成,所以我正在尝试这样做,但launch协程内部的代码似乎没有运行。我已经放置了日志语句,但它们没有运行,并且似乎没有结果打印在我的文本视图上。调试器还说,当我在其上放置断点时,没有可运行的代码。我在这里搞砸了什么?

private fun bindUI() = launch(Dispatchers.Main) {
        // fetch the location
        val weatherLocation = viewModel.weatherLocation.await()

        // Observe the location for changes
        weatherLocation.observe(viewLifecycleOwner, Observer { location ->
            if (location == null) return@Observer
            //TODO:sp update the location text view
            launch(Dispatchers.Main) {
                val task = updateLocation(location)
                locationTxtView.text = task[0].countryName
            }
        })
    }
Run Code Online (Sandbox Code Playgroud)

有趣的是updateLocation()

private suspend fun updateLocation(location: WeatherLocation): MutableList<Address> {
    return async(Dispatchers.IO) {
        val geocoder = Geocoder(activity, Locale.getDefault())
        val addr = geocoder.getFromLocation(location.latitude, …
Run Code Online (Sandbox Code Playgroud)

geocoding kotlin android-studio kotlin-coroutines

5
推荐指数
0
解决办法
1240
查看次数

M1 上的 Flutter:从 Windows 移动到 Mac 后 GoogleMapsBase 和 Flutter.h 未发现错误

我已经在我的 Windows 机器上开发 flutter 应用程序有一段时间了,最​​近切换到带有 M1 芯片的 mac mini。该应用程序使用谷歌地图,但当我尝试在 iOS 设备上运行它时,出现以下错误:

\n
Launching lib/main.dart on iPhone 13 Pro Max in debug mode...\nXcode build done.                                           72.1s\nFailed to build iOS app\nError output from Xcode build:\n\xe2\x86\xb3\n    --- xcodebuild: WARNING: Using the first of multiple matching destinations:\n    { platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }\n    { platform:iOS Simulator, id:1BBC3B77-3A9D-4F09-892A-34C7059C2430, OS:15.0, name:iPad (9th generation) }\n    { platform:iOS Simulator, id:BD58EEBD-CC57-418D-B33A-B381EB89E4BE, OS:15.0, name:iPad Air (4th generation) }\n    { platform:iOS Simulator, id:01C2C865-7ED0-4B1E-B391-6546DE9FA12B, OS:15.0, name:iPad Pro (9.7-inch) }\n …
Run Code Online (Sandbox Code Playgroud)

ios visual-studio-code flutter apple-m1

5
推荐指数
1
解决办法
2252
查看次数

使用地理围栏时如何通知来自 BroadcastReceiver 的调用活动

我根据地理围栏文档定义了一个 BroacastReceiver,以便在用户与地理围栏交互时接收 ENTRY 和 EXIT 更新。我的问题是,该应用程序将在路上使用,因此,当用户驾驶并进入地理围栏时,我会收到有关此情况的通知,并且当他退出地理围栏时也会发生同样的情况。但是,当收到退出事件时,我需要从客户端和 Google 地图地图中删除触发的地理围栏。这两个都存在于我的 MapsActivity 中(这是我根据文档设置接收器和事件通知过程的地方),因此我想removeGeofences(...)从接收器调用我的活动的方法。我查看了大量有关此事的帖子,但似乎没有一个涵盖地理围栏用例。我尝试通过代码动态地声明接收器,而不是通过清单静态地声明,但在这种情况下,我需要意图过滤器,而我无法找到地理围栏的意图过滤器。关于如何实现这一目标有什么想法吗?

广播接收器:

class GeofenceReceiver : BroadcastReceiver() {
    private val TAG = GeofenceReceiver::class.java.simpleName

    override fun onReceive(context: Context?, intent: Intent?) {
        val geofencingEvent = GeofencingEvent.fromIntent(intent)
        if (geofencingEvent.hasError()) {
            val errorMessage = GeofenceStatusCodes
                .getStatusCodeString(geofencingEvent.errorCode)
            Log.e(TAG, "error: $errorMessage")
            return
        }

        // Get the transition type.
        val geofenceTransition = geofencingEvent.geofenceTransition

        // Test that the reported transition was of interest.
        if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
            geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT
        ) {

            // Get the geofences that …
Run Code Online (Sandbox Code Playgroud)

android google-maps broadcastreceiver kotlin android-geofence

4
推荐指数
1
解决办法
452
查看次数