在nodejs的官方网站(https://nodejs.org/api/timers.html#timers_setimmediate_callback_arg)中,据说:
setImmediate()函数在I/O事件的回调之后和触发setTimeout和setInterval设置的定时器之前调度"立即"执行回调.
但是在下面的代码中,setTimem()函数在setImmediate()之前执行.为什么?
setImmediate(function A() {
setImmediate(function B() {
console.log(1);
setImmediate(function D() { console.log(2); });
setImmediate(function E() { console.log(3); });
});
setImmediate(function C() {
console.log(4);
setImmediate(function F() { console.log(5); });
setImmediate(function G() { console.log(6); });
});
});
setTimeout(function timeout() {
console.log('TIMEOUT FIRED');
}, 0)
Run Code Online (Sandbox Code Playgroud)
结果:
TIMEOUT FIRED 1 4 2 3 5 6
我写了另一个例子,也在这里setTimeout工作setImmediate.
setTimeout(function timeout() {
console.log('TIMEOUT-1 FIRED');
}, 0)
setTimeout(function timeout() {
console.log('TIMEOUT-2 FIRED');
}, 0)
setImmediate(function D() { console.log(1); });
setImmediate(function …Run Code Online (Sandbox Code Playgroud) 我的应用程序要求用户提供相机权限。如果用户拒绝该权限,则在重新启动时再次请求他的权限。这一次,向用户显示“不再询问”复选框。如果用户选择从不再次询问复选框,则应用程序永远不会请求许可。没关系。问题是我的手机永远不会忘记这个选择,它会记住这个选择。我删除了应用程序,清除了所有数据,但没有任何效果。
当我删除应用程序并重新安装它时,该应用程序仍然无法请求许可。我打开设置-> 应用程序设置->然后我手动为我的应用程序授予了必要的权限。没关系。然后,我删除并重新安装它。但是应用程序仍然不能请求许可。我不想在每次安装时手动授予我的应用程序权限。如何重置“不再询问”复选框的选择。
if (Build.VERSION.SDK_INT >= 23)
{
int hasPermission = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA);
if (hasPermission != PackageManager.PERMISSION_GRANTED)
{
if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA))
{
getErrorDialog("You need to allow Camera permission." +
"\nIf you disable this permission, You will not able to add attachment.", MainActivity.this, true).show();
}
return;
}
}
public AlertDialog.Builder getErrorDialog(String message, Context context, final boolean isFromCamera) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle(getString(R.string.app_name)).setMessage(message);
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (Build.VERSION.SDK_INT …Run Code Online (Sandbox Code Playgroud) 我大约24小时前注册了admob.确认邮件来自admob.我在我的应用程序中添加了admob id.当我通过点击android studio中的运行按钮将我的应用程序安装到真实设备时,真正的广告显示正常.所以我的admob id工作正常.
但是,当我生成签名的apk并使用Android Studio终端通过apk install ...命令将apk安装到我的设备时,真实广告不会显示.我首先认为这个问题与proguard有关,但它与proguard无关.因为我停用了proguard并且真正的广告仍未显示.可能是什么问题?
build.gradle(app level):
apply plugin: 'com.android.application'
apply plugin: 'com.bugsnag.android.gradle'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "...."
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'jp.wasabeef:recyclerview-animators:2.2.4'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.nex3z:flow-layout:1.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-ads:17.1.1' …Run Code Online (Sandbox Code Playgroud) 我正在学习指针,但我被下面的示例程序所困扰.它应该是转换char**为char*,但我不明白该程序背后的逻辑.该计划在做什么?
#include <iostream>
using namespace std;
int main() {
char *notes[] = {"cpp","python","java","mariadb"};
void * base = notes; // notes and base, holds the address of note's first element
void * elemAddr = (char*) base + 3* sizeof(char *); // i didn't understand this line???
cout << *(char **)elemAddr; // and this line
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我不明白为什么我会接受这个"奇怪"的错误.我读过类似的问题,但没有回答我的问题.如果我在main函数而不是全局范围内定义数组,则没有错误.但是假设我必须在全局范围内定义这个数组.为什么我会接受这个错误?这是代码:
#include <iostream>
#include <cstring>
using namespace std;
int right[1005];
int main()
{
memset(right,0,sizeof(right));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
memset2.cpp: In function ‘int main()’:
memset2.cpp:9:9: error: reference to ‘right’ is ambiguous
memset(right,0,sizeof(right));
^
memset2.cpp:6:5: note: candidates are: int right [1005]
int right[1005];
^
In file included from /usr/include/c++/4.8/ios:42:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from memset2.cpp:1:
/usr/include/c++/4.8/bits/ios_base.h:924:3: note: std::ios_base& std::right(std::ios_base&)
right(ios_base& __base)
^
memset2.cpp:9:24: error: reference to ‘right’ is ambiguous
memset(right,0,sizeof(right));
^
memset2.cpp:6:5: note: candidates are: int right [1005]
int right[1005];
^
In …Run Code Online (Sandbox Code Playgroud) 以下代码引自:http : //examples.javacodegeeks.com/core-java/io/fileoutputstream/java-io-fileoutputstream-example/
尽管OutputStream是一种抽象方法,但是在下面的代码中,OutputStream对象用于写入文件。
Files.newOutputStream(filepath))返回OutputStream。然后,out的类型为OutputStream,而out引用OutputStream。
当OutputStream是抽象类时,怎么可能呢?
package com.javacodegeeks.core.io.outputstream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class FileOutputStreamExample {
private static final String OUTPUT_FILE = "C:\\Users\\nikos\\Desktop\\TestFiles\\testFile.txt";
public static void main(String[] args) {
String content = "Hello Java Code Geeks";
byte[] bytes = content.getBytes();
Path filepath = Paths.get(OUTPUT_FILE);
try ( OutputStream out = Files.newOutputStream(filepath)) {
out.write(bytes);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud) android ×2
c++ ×2
admob ×1
casting ×1
io ×1
java ×1
javascript ×1
node.js ×1
outputstream ×1
permissions ×1
pointers ×1
proguard ×1