使用execute()和有executeOnExecuter()什么区别?
execute()默认情况下如何执行任务?(串行还是并联?)
什么应该用于新的SDK> 16?
将并行执行(THREAD_POOL_EXECUTOR)用于任务而不是串行是一个好习惯,即使它对应用程序无关紧要,还是取决于AsyncTask将要执行的s 的数量?
我有一个应用程序,要求用户登录然后呈现活动.还在登录上启动服务,该服务使用位置管理器来跟踪其当前位置.一切都运行正常,直到应用程序处于待机模式(在背景中关闭应用程序超过约1小时)
我怎么能阻止这个?
据我所知,如果我有一个前台服务运行,操作系统不应该杀死应用程序..所以我做错了什么?我正在测试的操作系统是奥利奥
登录时启动服务:
startService(intent);
Run Code Online (Sandbox Code Playgroud)
服务:
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
@Override
public void onCreate() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Notification notification = updateNotificationContent(); // the service notification
if (notification == null)
stopSelf();
startForeground(id, notification);
}
Run Code Online (Sandbox Code Playgroud)
我添加了日志记录来销毁活动和服务的功能以检测何时发生这种情况但是当这种行为发生时从未写入日志(当然,当我销毁应用程序时它会进入正常情况)
正如标题所述,我按照以下教程在模块化 android 项目中使用 buildSrc 和 Kotlin 进行 Gradle 依赖管理:https ://caster.io/lessons/gradle-dependency-management-using-kotlin-and-buildsrc- for-buildgradle-autocomplete-in-android-studio
它一切正常,但问题是如果有任何库的版本有更新,我如何收到通知?(我没有收到图书馆的通知,它被标记为显示有更新)
还有另一种方法吗?
使用下面的代码,我能够发送一个大文件到服务器,但我似乎无法找出如何发送文件的文本.(发送文件加上额外的数据(用户名,密码..)例如).并在服务器端接收它.
FileInputStream fileInputStream = new FileInputStream(new File(
pathToOurFile));
URL url = new URL(urlServer);
connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setChunkedStreamingMode(1024);
// Enable POST method
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type",
"multipart/form-data;boundary=" + boundary);
outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
String connstr = null;
connstr = "Content-Disposition: form-data; name=\"uploadedVideos\";filename=\""
+ pathToOurFile + "\"" + lineEnd;
outputStream.writeBytes(connstr);
outputStream.writeBytes(lineEnd);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// Read file
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
try {
while …Run Code Online (Sandbox Code Playgroud) 我正在尝试将文档目录中的文件复制到文档目录中的目录,但出现错误无法将\xe2\x80\x99t 复制到\xe2\x80\x9cDocuments\xe2\x80\x9d,因为带有同名已经存在。
\n\n任何帮助,将不胜感激。
\n\n这是我的代码:
\n\nlet documentsPath = NSURL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0])\n let logsPath = documentsPath.URLByAppendingPathComponent("Logs")\n\n\n let fileURL = documentsPath.URLByAppendingPathComponent("Database.db")\n\n do {\n try NSFileManager.defaultManager().copyItemAtURL(fileURL, toURL: logsPath)\n } catch let error1 as NSError{\n RZLog.Error ("Error: \\(error1.localizedDescription)")\n }\nRun Code Online (Sandbox Code Playgroud)\n 我遵循了这个教程,自定义字体显示在我的故事板上但是当我执行我的应用程序(在模拟器或设备上)时,字体没有反映出来.有谁可以帮忙.这就是我做的:
1- downloaded a .ttf file and copied it to my project
2- added "Fonts Provided By Application" in info.plist and added a row having the name of my custom font.
3- opened storyboard and selected the UILabel i want to have a custom font for, and selected the font as custom then selected my font. the font was shown on the storyboard correctly.
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
我有一个IntentService,使用改造执行webservice调用,然后成功时将执行响应(查询集).webservice调用正在成功完成并且一切正常,但是在执行查询时,UI会在执行完成时冻结然后继续.
意图服务不应该在后台执行任务而不影响UI吗?
代码简化:
@Override
public void success(Response iu, Response response) {
//get respose (set of queires then loop over them and execute them.
for (int i = 0; i < contentArray.length; i++) {
String query = contentArray[i];
MainActivity.myDataBase.execSQL(query);
} //the amount of queries can reach 100
Run Code Online (Sandbox Code Playgroud)
如果你想发布更多代码,我会
在我的ViewController中,我使用StoryBoard在ScrollView中添加了一个ScrollView和一个视图(在ScrollView和View上设置了约束).现在在我的代码中我使用View来动态添加其他视图.正在添加视图,但我的问题与滚动有关.我能够滚动,但它不滚动到最后一个视图...我尝试做以下
override func viewDidLayoutSubviews() {
ScrollView.contentSize.height = contentView.frame.height
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,我也注意到内容视图(我正在添加视图)高度是打印736,viewDidLayoutSubviews()即使我添加更多视图当然应该增加其大小.
请任何帮助将不胜感激.
我正在将视图添加到内容视图,如下所示:
let Description = UILabel(frame: CGRectMake(20, CGFloat(position), self.view.frame.size.width-40, 40))
Description.addConstraint(NSLayoutConstraint(item: view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 40))
Description.addConstraint(NSLayoutConstraint(item: view, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: self.view.frame.size.width-40))
contentView.addSubview(Description)
// i don't know if i should add constraints but i added anyway
Run Code Online (Sandbox Code Playgroud)