小编sty*_*972的帖子

Android Listen Home按钮

如果应用程序包含某些默认意图,是否可以唯一地监听主页按钮?我已经检查了生命周期方法,但是当我启动默认意图和主页按钮时它将执行.

android

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

是否限定方法调用会降低Java中的性能?

我猜测以下两个函数编译为完全相同的字节码,但我想问一下这个问题.是否在不需要降低性能的情况下限定方法调用?

例如:

package com.my;

import android.app.Activity;
import android.os.Bundle;

public class Main extends Activity {

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        this.setContentView(R.layout.main); // Fully qualified 
        setContentView(R.layout.main);      // Not fully qualified
    }

}
Run Code Online (Sandbox Code Playgroud)

标准是使用后者,但完全合格的呼叫this.setContentView()是否有任何负面影响?

java methods performance android bytecode

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

document.getElementById("id")有效,但$("#id")不是jQuery

我正在迭代一些元素,我发现它document.getElementById("id")有效,但$("#id")没有.为什么?

编辑:我想发布代码不会有什么坏处?

function myFunction() {
    var token, tokens, id, input;
    $("[id^=\"some_id_\"]").each(function() {
        tokens = this.id.split("_");
        id = tokens[tokens.length - 1];
        input = document.getElementById("some_form_element_" + id);  //WORKS
        //input = $("#some_form_element_" + id); //DOESNT, alerts undefined

        alert(input.value);
    });
}
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

PHP字符串文字和编译器优化

可能重复:
在php中,单引号与双引号是否有性能优势?

我想知道如果PHP代码中使用时,需要一个性能命中"定义字符串,当s 不包含变量相比,'在不进行额外的解析.

例如,PHP将尝试解析由"但未定义的字符串内的变量'.

$myString = "Greetings earthlings!";
echo '$myString'; //literally outputs the string '$myString'
echo "$myString"; //literally outputs the string "Greetings earthlings"
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,我一直在编写这样的代码:

echo "Greetings earthlings";
Run Code Online (Sandbox Code Playgroud)

我一直在浪费周期吗?或者是PHP智能/优化的不够了解我真正的意思是:

echo 'Greetings earthlings';
Run Code Online (Sandbox Code Playgroud)

php optimization php-opcode

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

如何在swift中将数据从iphone发送到watchkit

我正在做一个示例项目,我喜欢将数据从iphone发送到WatchKit.我不知道该怎么做.任何帮助将不胜感激.提前致谢

swift watchkit

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

RLMException:不能使用不兼容的类型持久保存属性"id",但是不存在

我正在尝试新建这个对象的实例:

class MyAwesomeRealmObject: BaseRealmObject {

    var field:     String = ""
    var thing:     String = ""
    var whatever:  String = ""
    var something: String = ""
    var key:       String = ""

    var cards = [OtherRealmObject]()//wasnt this either

    override static func primaryKey() -> String? {
        return "key"
    }

//    override static func ignoredProperties() -> [AnyObject] {
//        return ["id"] //this didnt work either
//    }

}
Run Code Online (Sandbox Code Playgroud)

这是父类

class BaseRealmObject: Object {
    //nothing really here, just extending realm's Object
}
Run Code Online (Sandbox Code Playgroud)

我得到了这个运行时异常.

2015-08-19 10:03:53.388 …
Run Code Online (Sandbox Code Playgroud)

entity runtime-error realm ios swift

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

如何配置命令行git以使用ssh密钥

当我git pull通过命令行执行操作时,它总是要求我的github用户名和密码.我想告诉它在github中使用ssh密钥,再也不用担心了.你怎么做到这一点?

git authentication command-line github ssh-keys

0
推荐指数
2
解决办法
2600
查看次数

在列表上调用.sort时AbstractList UnsupportedOperationException

我正在使用Collections.sort()对列表进行排序,这似乎在我测试它的所有方式中都可以正常工作。我的一些用户崩溃了。

Caused by java.lang.UnsupportedOperationException
    java.util.AbstractList.set (AbstractList.java:681)
    java.util.AbstractList$FullListIterator.set (AbstractList.java:143)
    java.util.Collections.sort (Collections.java:1909)
    com.myapp.MyFragment.myMethod (MyFragment.java:225)
Run Code Online (Sandbox Code Playgroud)

但是,我正在做的就是尝试对列表进行排序

private void myMethod(List<MyThing> myThings) {

    Collections.sort(myList, (thing1, thing2) -> Long.compare(thing2.getLongValue(), thing1.getLongValue()));
Run Code Online (Sandbox Code Playgroud)

我注意到这在Android 8及更高版本上不会发生。它仅发生在5.0-7.1

该列表被实例化为ArrayList,进行填充,并设置为作为通用列表的类的实例的成员。然后将该对象与EventBus一起发布。然后使用Kotlin mapsortedByDescending函数映射并排序列表。然后将映射和排序的列表传递给myMethod()

这个Kotlin扩展正在生成传递给此方法的列表:

fun List<MyThing>.mapAndSort(context: Context): List<MyThing> {
    return mapNotNull {
        when (it.type) {
            type -> it.getTyped(context) //all of these return polymorphic MyThings
            anotherType -> it.getAnotherTyped(context)
            someOtherType -> it.getSomeOtherTyped(context)
            yetAnotherType -> it.getYetAnotherType(context)
            yetOneMoreType -> it.getYetOneMoreType(context)
            finallyLastTyope -> it.getFinallyLastType(context)
            else -> null
        }
    }.sortedByDescending { it.longValue }
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经看到此列表是java.util.Arrays$ArrayList和 …

java collections android exception kotlin

0
推荐指数
1
解决办法
233
查看次数

在mockK中存根定向配置Android资源

我正在尝试使用 MockK来存根实例orientation的值,以便我可以在我的应用程序中测试一些横向与纵向行为。ConfigurationResources

不幸的是,我遇到了一些我从未见过的轻松模拟发生的事情。

import android.content.res.Configuration
import android.content.res.Resources

...

    @Test
    fun `When behavior, verify result based on orientation`() {

        val resources = mockk<Resources>(relaxed = true) {
            every { configuration } returns mockk(relaxed = true) {
                every { orientation } returns Configuration.ORIENTATION_LANDSCAPE // Line 36, see stack trace
            }
        }

        ...
    }
Run Code Online (Sandbox Code Playgroud)

第 36 行抛出此异常:

io.mockk.MockKException: Missing calls inside every { ... } block.

    at io.mockk.impl.recording.states.StubbingState.checkMissingCalls(StubbingState.kt:14)
    at io.mockk.impl.recording.states.StubbingState.recordingDone(StubbingState.kt:8)
    at io.mockk.impl.recording.CommonCallRecorder.done(CommonCallRecorder.kt:47)
    at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:60)
    at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:30)
    at io.mockk.MockKDsl.internalEvery(API.kt:92)
    at io.mockk.MockKKt.every(MockK.kt:98) …
Run Code Online (Sandbox Code Playgroud)

android kotlin mockk

0
推荐指数
1
解决办法
591
查看次数