小编Art*_*aev的帖子

Google Api客户端有时在onConnected中为NULL

我实施GoogleApiClient如下:

 mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, 0 /* clientId */, this)
                .addApi(LocationServices.API)
                .addApi(Places.GEO_DATA_API)
                .addConnectionCallbacks(this)
                .build();
Run Code Online (Sandbox Code Playgroud)

但在onConnected方法中我检查mGoogleApiClient => value null.在这种情况下,我尝试重新构建googleApiClient但我收到错误:

  java.lang.IllegalStateException: Already managing a GoogleApiClient with id 0
Run Code Online (Sandbox Code Playgroud)

请帮助我理解为什么mGoogleApiClient有时候是NULL,因为它已连接:|.(注意.我检查了所有源代码,我从未将GoogleApiClient设置为NULL).

谢谢!

更新

我尝试使用最新版本的播放服务后,我的问题现在解决了.

谢谢大家的帮助.

android google-api-client

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

绘制逻辑回归的决策边界

我正在实施逻辑回归.我设法从中获取概率,并且能够预测2级分类任务.

我的问题是:

对于我的最终模型,我有权重和训练数据.有2个功能,所以我的重量是一个2行的向量.

我如何绘制这个?我看过这篇文章,但我不太明白答案.我需要等高线图吗?

matplotlib scikit-learn logistic-regression

15
推荐指数
2
解决办法
3万
查看次数

使用ABI拆分启用externalNativeBuild

我已经切换到cmake构建系统了ndk-build.但无法获得APK拆分功能.

这是我的app build.gradle文件

构建的结果只有一个文件 - foo.bar-armeabi-v7a-release-1.5.1.apk.
如果我正在为x86模拟器构建应用程序,结果是foo.bar-x86-release-1.5.1.apk

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileOptions.encoding = 'ISO-8859-1'
    compileSdkVersion CompiledSdkVersion
    buildToolsVersion BuildToolsVersion

    defaultConfig {
        applicationId "foo.bar"
        minSdkVersion MinSdkVersion
        targetSdkVersion TargetSdkVersion
        versionCode VersionCode
        versionName VersionName
        vectorDrawables.useSupportLibrary = true

        externalNativeBuild {
            cmake {
                cppFlags "-fexceptions", "-std=c++11"
            }
        }

        ndk { …
Run Code Online (Sandbox Code Playgroud)

android android-ndk android-studio build.gradle android-gradle-plugin

14
推荐指数
1
解决办法
1341
查看次数

将布局XML扩展为自定义LinearLayout会创建冗余的LinearLayout视图

我正在创建一个自定义LinearLayout组件.它被设计为模仿a的一些功能ListView,用于a ScrollView,因为我不能/不应该使用ListView内部a ScrollView.我们称之为CustomListView.此外,我正在创建另一个自定义LinearLayout来表示此伪列表视图中的每个项目,我们称之为NewItemView.

无论如何,在初始化NewItemView时,我通过膨胀布局XML来设置它.布局XML将a声明LinearLayout为其根视图,并且与布局类似simple_list_item_multiple_choice.xml.

总的来说,主要活动有一个CustomListView.我们呼吁addItem(Item item)有关CustomListView到一个新的项目添加到列表中,这在现实中,创建一个新的NewItemView,并从项目类数据填充它.

我正在这样膨胀newListItem.initListItem(Context context):

 ((Activity)getContext())
            .getLayoutInflater()
            .inflate(R.layout.list_item, this, true);
Run Code Online (Sandbox Code Playgroud)

这实际上有效!但是,我遇到的问题是在使用Monitor进行检查时,LinearLayout只有坐在列表中的每个项目旁边都有一个冗余.我的理解是,这通常是一个坏主意.还有的LinearLayoutCustomListView,那么对于每一个项目,有一个LinearLayout,只有一个子女; 一个LinearLayout!最后一个包含实际的孩子.

我希望它与我基于LinearLayout创建自定义组件,然后在其根目录下使用LinearLayout来扩展布局这一事实有关.

android android-layout android-linearlayout

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

无法找到默认活动类名称

我正在处理将facebook登录链接到我的Android应用程序的过程.在一些教程中,我被要求在Facebook开发者网站上注册我的应用程序,我在那里做了所有事情,但我在Android Studio中找不到"默认活动类名称"我在下面提供了清单文件

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="in.evago.evago">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />

        <!-- Front Page -->
        <activity
            android:name=".Frontpage"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>
        <!-- Search results activity -->


<activity
        android:name=".SearchResultsActivity"
        android:label="@string/title_activity_searchable"
        android:launchMode="singleTop"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
    </activity>
    <!-- Search results activity Ends -->

</application>
Run Code Online (Sandbox Code Playgroud)

请帮我找到"默认活动类名"

java android facebook android-studio

7
推荐指数
2
解决办法
5037
查看次数

指定的消息队列同步屏障令牌尚未发布

我有一个作为绑定服务的应用程序。我正在向服务发送消息,但有时会出现以下错误:

E/AndroidRuntime(28216): java.lang.IllegalStateException: 指定的消息队列同步屏障令牌尚未发布或已被删除。

有时我会收到此错误:

android.util.AndroidRuntimeException: { what=888 when=0 } 此消息已被使用。

有时用户界面只是冻结。我通过处理程序从服务到活动进行通信,反之亦然。

 public void init(IBinder service){
    playerService = new Messenger(service);
    setBound(true);
    try {
        Message msg = Message.obtain(null, PlayerService.MSG_REGISTER_CLIENT);
        msg.replyTo = messenger;
        playerService.send(msg);
        while(!messageQueue.isEmpty()){
            playerService.send(messageQueue.remove());
        }
    } catch (RemoteException e) {
        // In this case the service has crashed before we could even do anything with it
        Log.d(Player.TAG, "problem binding player messenger " + e.getMessage());
    }
}
Run Code Online (Sandbox Code Playgroud)

这是第二次调用时始终会导致冻结的方法。

public void play(String url) {
    Message msg = Message.obtain(null, PlayerService.PLAY, 0, 0);
    msg.setData(getURLBundle(url)); …
Run Code Online (Sandbox Code Playgroud)

android android-handler

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

在自定义列表视图上调用 notifyDatasetChanged() 后继续关注 TextView?

我有一个ListView适配器,当我修改我的TextView,我呼吁notifyDataSetChanged()addTextChangeListener()方法。但是我的 TextView 失去了焦点。我如何保持焦点,覆盖notifyDataSetChanged()?

我这样做但没有用

@Override
public void notifyDataSetChanged(){
    TextView txtCurrentFocus = (TextView) getCurrentFocus();
    super.notifyDataSetChanged();
    txtCurrentFocus.requestFocus();
}
Run Code Online (Sandbox Code Playgroud)

android listview android-arrayadapter notifydatasetchanged

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

java.lang.IllegalStateException:已经调度了TimerTask:在Android中合理使用Timer和TimerTask

我编写了一个连接到服务器的应用程序,并向他发送ping命令,服务器用pong命令回答.

我想实现连接超时机制.我想它将遵循:

  • 客户端使用timertask和delay 发送ping并启动计时器
  • 当客户端收到pong时,timertask被取消.

另外,我想优化内存.所以,每次发送ping命令时都不要重新创建TimerTask .我尝试下面的代码:

private final Timer mSystemLogoutTimer = new Timer();
private final TimerTask mLogoutTask = new TimerTask() {

    @Override
    public void run() {
        mMessageInterface.onConnectionTimeout();
        cancel();
    }
};

private void ping() {
    sendRequest(RequestBuilder.formPing());
    mSystemLogoutTimer.schedule(mLogoutTask, CoreConst.PING_ANSWER_DELAY);
}

private void onPong() {
    mLogoutTask.cancel();
}
Run Code Online (Sandbox Code Playgroud)

但是当我第二次尝试安排TimerTask时出现以下错误:

java.lang.IllegalStateException: TimerTask is scheduled already
at java.util.Timer.scheduleImpl(Timer.java:572)
at java.util.Timer.schedule(Timer.java:459)
Run Code Online (Sandbox Code Playgroud)

我不明白,因为我打电话cancel()给TimerTask.

请告诉我我做错了什么.谢谢你的回答!

android exception timer

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

两种方法之间更新Android App Widget有什么区别?

我在网上/书中读到了一些关于App Widget的例子,更新小部件的正常例子是onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds)AppWidgetProvider的方法,如下所示:

final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
 int appWidgetId = appWidgetIds[i];
 RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.mywidget_layout);
 updateViews.setTextViewText(R.id.mytext, "updated text");

 appWidgetManager.updateAppWidget(appWidgetId, updateViews);    
}
Run Code Online (Sandbox Code Playgroud)

它会循环更新每个小部件.

但是现在,我必须实现一个App Widget,它在BroadcastReceiver onReceive(Context context, Intent intent)方法中更新,因为没有传入int [] appWidgetIds.所以我实现了这样的代码:

RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.mywidget_layout);
updateViews.setTextViewText(R.id.mytext, "updated text");

ComponentName myComponentName = new ComponentName(context, AndroidBatteryWidgetProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(myComponentName, updateViews);
Run Code Online (Sandbox Code Playgroud)

它没有逐个更新小部件,但实际上所有小部件都立即更新.即使它按我的意愿工作,但我很困惑为什么不需要像以前一样逐个更新所有小部件.

两种方法有什么区别?

我可以发送另一个广播BroadcastReceiver.onReceive()来触发AppWidgetProvider.onUpdate()吗?怎么样?

android widget broadcastreceiver android-appwidget

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

iOS 11 以下命名颜色的兼容性

我需要在运行在 iOS 8+ 上的 iOS 应用程序中实现暗模式。此外,我在颜色资产中定义了自定义颜色,其中包含用于浅色和深色外观的 RGB 代码。

问题是 iOS 11 之前不支持命名颜色,但我只能使用命名颜色来支持两种外观 - 深色和浅色。

有没有办法实现向后兼容?

xcode ios ios8 xcode11

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