小编pro*_*m85的帖子

Setting TextView text to static text crashes (rarely) with ArrayIndexOutOfBoundsException

By simply setting a TextViews text to a string defined in code (that never can be null) I sometimes get an ArrayIndexOutOfBoundsException, this only happens in my live app, I never had this issue on any test device yet... And it seems to happen sometimes only, the user tells me it happens once and the next time everything works again. Any ideas what could be the cause here? For me, it looks like this crash should never ever …

android indexoutofboundsexception kotlin

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

Android UI更新线程 - 保存并恢复它

我该怎么做呢?

我有一个秒表,我正在保存它的状态onSaveInstance并恢复它的状态onRestoreInstance......

现在我有以下问题:如果我停止线程onSaveInstance并且屏幕被锁定或关闭,onRestoreInstance则不会被调用并且秒表不会继续...
如果我不停止它,则秒表在后台运行并且即使屏幕关闭或活动不再活动...

那么处理这种事情的常用方法是什么?

PS:
我甚至有一个工作解决方案,一个局部变量来保存onStop事件中的运行状态并在事件中重新启动线程onStart......但我仍然想知道是否有一个使用android系统本身的"默认"解决方案.. ..

android state restore save

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

带有嵌套 RecyclerView 的 RecyclerView - 使嵌套的 RecyclerView 作为整个视图可点击

我使用显示条目列表的 RecyclerView。每个条目托管另一个 RecyclerView,它是一个图像列表。

我现在想让这个嵌套的 RecyclerView 可点击,不是它的项目,而是整个视图。

我怎样才能做到这一点?

问题:

  • 为嵌套的 RecyclerView 的主视图设置 onClickListener 确实有效,但前提是我在 RecyclerView 本身之外单击
  • 单击嵌套的 RecyclerView 不会将单击传递给父视图(我什至尝试将 clickable、focusable、focusableIntouch 设置为 false,但仍然没有委托触摸,而是由嵌套的 RecyclerView 消耗...

这是包装适配器的视图:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="0dp"
    android:layout_margin="5dp"
    android:foreground="?android:attr/selectableItemBackground" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:id="@+id/rlTop"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:text="Datum"
                android:textStyle="bold"
                android:id="@+id/tvDate" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="Info"
                android:id="@+id/tvInfo" />
        </RelativeLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rvData"
            android:clickable="false"
            android:focusableInTouchMode="false"
            android:focusable="false"
            android:layout_below="@+id/rlTop"
            android:layout_width="match_parent"
            android:layout_height="68dp"
            android:scrollbars="horizontal" />

    </RelativeLayout>

</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

android onclicklistener android-recyclerview

6
推荐指数
2
解决办法
5712
查看次数

存储访问框架 - 设置本地 DocumentFile 的最后修改日期

我想将文件从内部存储复制或移动到 SD 卡。我通过存储访问框架 (SAF) 和DocumentFile类来做到这一点...

复制是基于流的,DocumentFile并且没有像File设置上次修改日期的类的功能。

我知道,我将文件移动/复制到 SD 卡,所以我知道我创建了一个本地文件。有了这些信息,是否有可能以某种方式更新基础文件的最后修改日期DocumentFile

似乎您无法在不丢失上次修改日期的情况下将文件从内部存储移动/复制到 SD 卡...

阅读 - 工作

public long lastModified(DocumentFile file, Context context)
{
    long lastModified = 0;
    final Cursor cursor = context.getContentResolver().query(file.getUri(), null, null, null, null);
    try
    {
        if (cursor.moveToFirst())
            lastModified = cursor.getLong(cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_LAST_MODIFIED));
    }
    finally
    {
        cursor.close();
    }

    return lastModified;
}
Run Code Online (Sandbox Code Playgroud)

写作 - 不工作

public boolean setLastModified(DocumentFile file, Context context, long time)
{
    ContentValues updateValues = new ContentValues();
    updateValues.put(DocumentsContract.Document.COLUMN_LAST_MODIFIED, time);
    int updated = …
Run Code Online (Sandbox Code Playgroud)

android storage-access-framework documentfile

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

共享元素过渡-变换颜色

是否可以TextView通过共享的元素过渡为a动画,并在进行动画时另外从颜色过渡?

我正在从活动中的文本过渡到工具栏的文本,因此想在过渡时切换颜色...

android transition android-transitions shared-element-transition

6
推荐指数
0
解决办法
308
查看次数

MapView泄漏活动(没有位置服务)

我正在使用播放服务v9.8.0(没有位置服务权限),当我MapView在对话框片段中使用时,我仍然面临泄漏.我在我的代码示例中使用它,我用它来显示一个位置而我没有setMyLocationEnabled(因为我甚至没有这个设置的权限).

有没有人在我的代码中看到问题?我得到的漏洞就像这里的那样:MapView v2保持了Context.我这样做:

  • 创建一个对话框
  • 用a替换我的布局中的视图MapView(因为我也允许使用静态地图,所以我的默认视图ImageView在我的布局中,将替换为a MapView)

然后发生我的碎片泄漏MapView.mContext......

代码 - 对话片段

public class DialogMediaDetails extends DialogFragment
{
    private GoogleMap mGoogleMap = null;
    private MapView mMapView = null;

    @Override
    public final Dialog onCreateDialog(Bundle savedInstanceState)
    {
        Dialog dlg = ...; // create dialog
        View view = ...; // get view from dialog
        Location location = ...; // defined location
        initGoogleMap();
        return dlg;
    }

    private void initGoogleMap(Location location)
    { …
Run Code Online (Sandbox Code Playgroud)

android google-maps memory-leaks android-mapview

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

窗口小部件导致DeadObjectException - 小包裹上的事务失败

一旦我想要显示一个小部件并开始收听,我就会得到以下异常:

// the relevant stack trace, the rest is comming from my code 
// before the code line I posted below
java.lang.RuntimeException: system server dead?
    at android.appwidget.AppWidgetHost.startListening(AppWidgetHost.java:189)
    at com.my.app.utils.WidgetUtil.a(SourceFile:231)
    ...
    android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died
    at android.os.BinderProxy.transactNative(Native Method)
    at android.os.BinderProxy.transact(Binder.java:503)
    at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.startListening(IAppWidgetService.java:481)
    at android.appwidget.AppWidgetHost.startListening(AppWidgetHost.java:185)
    at com.my.app.utils.WidgetUtil.a(SourceFile:231)
    ...
Run Code Online (Sandbox Code Playgroud)

我的代码中的源代码如下:

 mAppWidgetManager = AppWidgetManager.getInstance(context);
 mAppWidgetHost = new AppWidgetHost(context, R.string.app_name);
 mAppWidgetHost.startListening(); // <= this line leads to the crash
Run Code Online (Sandbox Code Playgroud)

意见

  • 我的应用程序在很多手机上正常工作(实际上只有一个)
  • 以上崩溃只发生在一个用户设备上(SM-N910C(Samsung Note 4),Android 6.0.1)
  • 用户说,这些小部件在他的发射器中工作正常

有谁知道可能导致这种情况的原因是什么?这是我可以在我的应用程序中解决的问题吗?用户说小部件在他的发射器中正常工作......

android widget

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

在AndroidX迁移后找不到符号DataBindingComponent

将我的整个项目迁移到android x后,我再也无法进行编译了.

我得到以下100个错误:

e: M:\tmp\EverywhereLauncher\app\generated\data_binding_base_class_source_out\devWithoutTestWithAccessibilityDebug\dataBindingGenBaseClassesDevWithoutTestWithAccessibilityDebug\out\com\my\app\databinding\ActivityMainBinding.java:52: error: cannot find symbol
      @Nullable ViewGroup root, boolean attachToRoot, @Nullable DataBindingComponent component) {
                                                                ^
  symbol:   class DataBindingComponent
  location: class ActivityMainBinding
Run Code Online (Sandbox Code Playgroud)

我不知道从哪里继续.

我现在有两个问题.

  • 我只看到100个错误
  • 所有错误都是一样的,可能隐藏了真正的错误

我尝试了什么:

  • 我在我的项目中跟随build.gradle将打印错误的数量增加到10000:

    gradle.projectsEvaluated {
            tasks.withType(JavaCompile) {
                options.compilerArgs << "-Xmaxerrs" << "10000"
            }
        }
    
    Run Code Online (Sandbox Code Playgroud)

    这总是有效,但在这种情况下,它不会增加打印的错误

我接下来可以做些什么?

额外

android android-databinding androidx

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

获取设备的屏幕分辨率

我使用以下方法来获取屏幕大小:

public static Point getScreenSize(Context context)
{
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int w = wm.getDefaultDisplay().getWidth();
    int h = wm.getDefaultDisplay().getHeight();
    return new Point(w, h);
}
Run Code Online (Sandbox Code Playgroud)

在我的三星Galaxy s6上,此方法返回1080x1920 ...虽然我的设备的分辨率为1440x2560.

为什么?有没有更好的方法来获得适用于较新手机的屏幕分辨率?

编辑

我在服务中需要这种方法!我没有帮助的视图/活动,只有应用程序上下文!我需要REAL像素

android resolution screen-resolution

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

制作可卸载的系统应用程序

获得以下行为的前提条件是:

  • 应用程序无法卸载或禁用
  • app作为系统应用运行

到目前为止我所知道的:

  • rooted phone =>实际上,如果app是系统应用程序,则没有必要

我尝试了什么:

  • 安装app /system/app=>这使得它可以卸载但它仍然是可以停用的
  • 安装app /system/app-priv=>>与安装它相比没有任何改变/system/app
  • 安装app /system/app-priv/<app_name>=>这会破坏应用程序

思路

  • 要正确地将应用程序设置为系统应用程序,必须将其签名为系统应用程序?这可能吗?然后我可以把它移动到/system/app-priv/<app_name>?只是一个猜测,但我想在阅读其他内容时我已经读过这样的东西......如果这是真的,我如何将我的应用程序作为系统应用程序签名?
  • 我错了还是错过了什么?

我对替代解决方案持开放态度,我想要的是我的应用程序无法卸载也无法禁用

android system signature

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