小编Ana*_*zer的帖子

在 attachBaseContext 中使用 dagger-injected 对象

我需要SharedPreferencesattachBaseContext我的活动中访问我的实例(所以我可以在那里设置语言环境),但注入的SharedPreferences实例在那里不可用,因为注入发生在调用onCreate后运行的方法中attachBaseContext。我正在使用 dagger2 进行依赖注入。

知道如何避免创建新SharedPreferences实例吗?

编辑:

好的,所以我认为问题是我试图过多地使用匕首,我认为在这种情况下它根本不合适。在attachBaseContext每个活动的我有更新的语言环境,我这个提取更新逻辑到LocaleManager其需要访问SharedPreferences实例和Context我进去attachBaseContext。该SharedPreferences实例已经在 中AppModule,但我仍然无法将@Inject其添加到attachBaseContext调用之前的活动中,因为活动的注入发生在 之后attachBaseContext

android dagger-2

10
推荐指数
1
解决办法
1169
查看次数

如何在Android Iconnenerator上居中文本

我正在开发一个使用大量放置在地图上的标记的应用程序,我正在使用自定义ClusterRenderer来显示它们.问题是我无法在自定义标记图标的中心绘制群集的大小,请参阅附带的屏幕截图.我已经尝试将contentPadding添加到IconGenerator,但仍然没有运气,因为显示的位数变化.你能帮我把文字集中在生成的图标上吗?

码:

 IconGenerator clusterIconGenerator = new IconGenerator(context);
 clusterIcon = context.getResources().getDrawable(R.drawable.map_cluster);
 clusterIconGenerator.setBackground(clusterIcon);

@Override
protected void onBeforeClusterRendered(Cluster<MyType> cluster, MarkerOptions markerOptions) {

    Bitmap clusterIcon = clusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(clusterIcon));
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

android bitmap google-maps-markers markerclusterer google-maps-android-api-2

9
推荐指数
1
解决办法
3909
查看次数

谷歌分析崩溃报告只显示第一行的堆栈跟踪

我的应用程序使用Google Analytics跟踪异常和崩溃(以及其他问题).我用这个函数来获取stacktrace:

public static void sendErrorReportViaGoogleAnalytics(Exception e) {

    e.printStackTrace();
    Tracker myTracker = EasyTracker.getTracker();
    myTracker.sendException(getDescription(e), false);
}

public static String getDescription(Exception t) {

    final StringBuilder result = new StringBuilder();
    result.append(t.toString());
    result.append(',');
    String oneElement;

    for (StackTraceElement element : t.getStackTrace()) {
        oneElement = element.toString();
        result.append(oneElement);
        result.append(",");
    }

    return result.toString();
}
Run Code Online (Sandbox Code Playgroud)

这很好用,在谈论异常时,我只是在我的异常处理代码的catch部分调用sendErrorReportViaGoogleAnalytics(),但是当遇到崩溃时,我只得到一行stacktrace,就像

Binary XML file line #11: Error inflating class fragment
Run Code Online (Sandbox Code Playgroud)

我设置

<bool name="ga_reportUncaughtExceptions">true</bool>
Run Code Online (Sandbox Code Playgroud)

在analytics.xml中,因为我正在使用EasyTracker.

如果发生崩溃,我该怎么做才能获得完整的堆栈跟踪?

android google-analytics crash-reports

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

android map v2上的聚类标记

最近我在一个Android项目中工作,我设法将标记添加到MapView,并将这些标记聚类在一起,如果它们彼此太靠近.现在我必须使用新的MapFragment - Google Maps Android API v2来做同样的事情.

现在标记已成功添加到地图中,但我无法设置群集部分,我找不到有关此主题的任何可用描述.您是否知道使用新API实现此目的的方法?

任何帮助将非常感激.

maps android android-mapview android-maps-v2

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

android.os.TransactionTooLargeException for ForegroundService通知

我正在编写一个可跟踪用户位置并在通知中显示旅程的距离,时间和价格的android应用,所有这些都在中跟踪ForegroundService。该服务跟踪位置,价格和时间,我每秒都在更新通知。我TransactionTooLargeException在生产中就得到了它,这是第一个通知更新,它仅在运行Android 8.0+的Samsung设备上发生。

这是正在发生的事情:

start从服务中调用方法:

public void start(MeasureService service) {
    service.startForeground(NOTIFICATION_ID, getNotification(0, 0, 0));
}
Run Code Online (Sandbox Code Playgroud)

update从服务中调用方法:

public void update(int price, float meters, long time) {
    mNotificationManager.notify(NOTIFICATION_ID, getNotification(price, meters, time));
}
Run Code Online (Sandbox Code Playgroud)

实际上,这些调用是彼此接连调用的,崩溃来自该update方法。(一个接一个地打电话)会不会有问题?

这是getNotification

private Notification getNotification(int price, float meters, long seconds) {
    if (mNotificationBuilder == null) {
        createNotificationBuilder();
    }
    return mNotificationBuilder
            .setCustomContentView(getSmallView(price))
            .setCustomBigContentView(getBigView(price, seconds, meters))
            .build();
}
Run Code Online (Sandbox Code Playgroud)

其中getSmallViewgetBigView方法是这样的:

private RemoteViews getSmallView(int price) {
    String priceText = …
Run Code Online (Sandbox Code Playgroud)

android android-notifications foreground-service

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

HttpLoggingInterceptor无法登录android版本

我的应用程式发布版本中的places API出现问题,如果我能看到来自的日志,它将对我有很大帮助OkHttpClient。我要添加一个HttpLoggingInterceptor,但只能看到调试版本的日志。我如何在发行版本中看到它们?

android okhttp

3
推荐指数
1
解决办法
523
查看次数