我有一个以 Activity 开头的应用程序,用于在显示主 Activity 之前加载内容。启动应用程序通常会执行MyApplication--> MyLoadingActivity--> MyMainActivity。其中MyMainActivity有一个带有 RecyclerViews 和其他东西的 ViewPager。MyMainActivity当导航到应用程序中的其他 Activity 或从其他 Activity 导航时,状态会正确保存和恢复,但从MyMainActivity通知启动时,所有状态都会被清除,因为 Android 会重新启动该 Activity。
通知是通过检查远程服务器更新的服务创建的。一旦发现更新,新数据就会存储在 SQLite 数据库中,并创建有关此的通知。当我单击此通知时,MyMainActicity已启动,但状态丢失。
按照官方指南,以下是我在服务中创建通知的方法:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.foo)
.setAutoCancel(true)
.setContentTitle("title")
.setContentText("text")
.setStyle(new NotificationCompat.BigTextStyle().bigText("A long text will go here if we are on Lollipop or above."));
Intent notifyIntent = new Intent(context, MyMainActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent notifyPendingIntent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(notifyPendingIntent);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); …Run Code Online (Sandbox Code Playgroud) 我有一个 gradle 任务来创建一个 jar 文件,其中包含要包含在 Android aar 库包中的 Java源文件。这些文件将作为 JNI 的 Javadoc 到同样捆绑在 aar 包中的 C++ 库。
我无法弄清楚如何包含jar 文件而不是编译其中的文件。jar 文件中的 Java 文件似乎已编译,这对我没有帮助 - 我只想包含它们,以便使用该 aar 包的开发人员可以使用它们。
创建的 jar 文件包含所有源文件,并且在其libs目录中的输出 aar 中,但它没有内容。
如何将 Java 源代码添加到我的 aar 中?
Jar 创建
Jar 是按如下方式创建的,并最终位于build/libs我的模块的文件夹中。
task generateMySources(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
artifacts {
archives generateMySources
}
preBuild.dependsOn(":myModule:generateMySources")
dependencies {
// The jar is included but it is …Run Code Online (Sandbox Code Playgroud) 我正在尝试在VBA中创建,放置和填充ComboBox的元素.我不明白我错过了什么,但我不知道该怎么做.我不有MSForms我的API(即我不能写Dim someComboBox As MSForms.ComboBox,因为它失败.是否有可能以某种方式进口吗?有人点我在正确的方向?
我想要实现的是,当用户单击一个按钮时,会创建一个包含各种项目(ComboBoxes,RadioButtons等)的新表单,因此我想以编程方式执行此操作.
我已经设置了PreferenceFragment两个布尔首选项.在Fragment当应用程序被关闭并重新打开,做工精细和设置存储.但是,在尝试阅读这些值时,我遇到了问题; 仅返回默认值.如果我调试getBoolean方法,SharedPreferences我看到本地HashMap的大小为0,因此返回默认值,如下所示:
public boolean getBoolean(String key, boolean defValue) {
synchronized (this) {
awaitLoadedLocked();
Boolean v = (Boolean)mMap.get(key); // <-- mMap is of size 0: return defValue
return v != null ? v : defValue;
}
}
Run Code Online (Sandbox Code Playgroud)
我发现这很奇怪,因为偏好值显然是存储并正确加载到PreferenceFragment.我错过了什么?
在Activity.onCreate():
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
Run Code Online (Sandbox Code Playgroud)
RES/XML /的preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="mm_preferences_category_recipe_preferences"
android:title="@string/mm_preferences_category_recipe_preferences_title" >
<CheckBoxPreference
android:key="@string/mm_preferences_numbers_as_fractions_key"
android:title="@string/mm_preferences_numbers_as_fractions_title"
android:summary="@string/mm_preferences_numbers_as_fractions_summary"
android:defaultValue="true" />
<CheckBoxPreference
android:key="@string/mm_preferences_comma_as_decimal_separator_key"
android:title="@string/mm_preferences_comma_as_decimal_separator_title"
android:summary="@string/mm_preferences_comma_as_decimal_separator_summary"
android:defaultValue="true" />
</PreferenceCategory>
</PreferenceScreen> …Run Code Online (Sandbox Code Playgroud) 我最近开始将Android构建从Ant移到Gradle,然后我想对我的C ++代码使用cmake。该构建当前运行良好,但是没有共享对象被复制到jniLibs文件夹中,然后在创建aar文件之前将它们放置在该文件夹中(这是一个库项目,当前在Windows 10上构建)。
我已经研究了使用进行构建时正在运行的任务./gradlew assembleDebug。他们是:
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:preReleaseUnitTestBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42221Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileLint UP-TO-DATE
:app:copyDebugLint UP-TO-DATE
:app:copyLibs
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:extractDebugAnnotations UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:mergeDebugProguardFiles UP-TO-DATE
:app:packageDebugRenderscript UP-TO-DATE
:app:packageDebugResources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:transformClassesAndResourcesWithSyncLibJarsForDebug UP-TO-DATE
:app:generateJsonModelDebug UP-TO-DATE
:app:externalNativeBuildDebug
building E:\path\to\app\Android\app\.externalNativeBuild\cmake\debug\libs\x86\libApp.so
building …Run Code Online (Sandbox Code Playgroud) 我试图获取我的iOS应用程序目录中的文件的路径Assets.xcassets,但我无法.看起来我应该NSBundle.mainBundle()以某种方式使用,但NSBundle 即使我导入Foundation或UIKit,Xcode也找不到.如果我在"NSBundle"上自动完成,我会得到以下选项:
NSBundleErrorMaximum
NSBundleErrorMinimum
NSBundleResourceRequest
NSBundleExecutableArchitecturePPC
NSBundleExecutableArchitectureI386
NSBundleExecutableArchitecturePPC64
NSBundleExecutableArchitectureX86_64
NSBundleOnDemandResourceInvalidTagError
Run Code Online (Sandbox Code Playgroud)
我不知道这些是为了什么.所以我的问题是:
NSBundle我的项目?Assets.xcassets/Database.dataset/database.txt?请注意,我能够获取文件的内容执行以下操作,但我想要文件的路径.
fileprivate static func readDatabaseFileFromAssets() -> NSDictionary
{
let databaseAsset = NSDataAsset(name: "Database", bundle: Bundle.main)
let json = try? JSONSerialization.jsonObject(with: databaseAsset!.data, options: JSONSerialization.ReadingOptions.allowFragments)
return json as! NSDictionary
}
Run Code Online (Sandbox Code Playgroud) 我有一个使用 Firebase 进行通知的 iOS 应用程序。通知已设置并正在运行,我现在需要接收/处理通知以相应地呈现视图控制器。我使用 Objective C 代码来调用我的 C++ 代码,因此我的项目中有一个桥接头,它主要是用 Swift 编写的。
我使用了firebase 文档中的这个示例(以及其他示例)。简而言之:遵守协议UNUserNotificationCenterDelegate并实现其功能。import UserNotifications我在班上也这样做AppDelegate。
现在,当进行这几个更改进行编译时,我收到这两个错误
找不到“UNUserNotificationCenterDelegate”的协议声明
未知类型名称“UNNotificationPresentationOptions”
对于生成的代码:
SWIFT_AVAILABILITY(ios,introduced=10)
@interface AppDelegate (SWIFT_EXTENSION(myapp)) <UNUserNotificationCenterDelegate>
- (void)userNotificationCenter:(UNUserNotificationCenter * _Nonnull)center willPresentNotification:(UNNotification * _Nonnull)notification withCompletionHandler:(void (^ _Nonnull)(UNNotificationPresentationOptions))completionHandler;
- (void)userNotificationCenter:(UNUserNotificationCenter * _Nonnull)center didReceiveNotificationResponse:(UNNotificationResponse * _Nonnull)response withCompletionHandler:(void (^ _Nonnull)(void))completionHandler;
@end
Run Code Online (Sandbox Code Playgroud)
经过一番尝试和错误后,似乎注释掉从 objC 到 Swift 的所有调用以及声明为 的所有 Swift 类型的使用都可以使@objc我的代码编译,并且桥接标头不再抱怨。这还包括在我的所有 Objective C 代码中进行注释#import "myapp-Swift.h"(这可能就是桥接标头不再抱怨的原因)。不幸的是,停止在 ObjC 中使用 Swift 类型是不可行的,因为对于一个看似很小的改变来说,它需要相当多的重写。
我想这可能在某种程度上表明了问题的根源,尽管我仍然不确定为什么或如何影响协议UNUserNotificationCenterDelegate。
这个问题与此有关.由于这是一个具体的问题,我在这里单独提出了这个问题.我已经尝试创建一个文本文件"foo.txt",将其读入我的Activity中:
File file = new File("/assets/foo.txt");
if ( file.exists() ){
txtView.setText("Exists");
}
else{
txtView.setText("Does not exist");
}
Run Code Online (Sandbox Code Playgroud)
"foo.txt"文件位于我的资源文件夹中,我已经验证它存在于操作系统中.我的TextView始终从上面的代码中获取文本"不存在".我试过去了
File file = new File("/assets/foo.txt");
Scanner in = new Scanner(file);
Run Code Online (Sandbox Code Playgroud)
同样,但这会产生以下内联错误:"未处理的异常类型FileNotFoundException".Eclipse然后建议涉及try/catch,这会删除错误,但它也不能正常工作.
我也尝试将我的资源文件夹设置为"用作源文件夹",但这没有任何区别.我也尝试使用原始文件夹,因为有几个人建议没用.我没有选择,真的需要帮助.应该很容易......
另一种尝试是去
AssetManager assetManager = getResources().getAssets();
InputStream is = assetManager.open("assets/foo.txt");
Run Code Online (Sandbox Code Playgroud)
但是这会在第二行产生内联错误:"未处理的异常类型IOException".
我正在创建一个iOS应用程序并使用Carthage构建外部库.由于我使用的库目前都是Swift 2和Swift 3,我有点紧张.因此,我希望有一个Swift 2分支和一个Swift 3分支进行开发,然后在库兼容Swift 3时合并它们.
但是,我无法为Carthage(版本0.18)选择构建哪个工具链.
这是我的Cartfile的内容:
# Swift 2 libraries
github "stephencelis/SQLite.swift" ~> 0.10.1
github "Haneke/HanekeSwift"
# Swift 3 libraries
#github "stephencelis/SQLite.swift" "swift3"
#github "Haneke/HanekeSwift" "feature/swift-3"
#github "kitasuke/PagingMenuController"
#github "Alamofire/Alamofire" ~> 4.0
Run Code Online (Sandbox Code Playgroud)
目前通过使用构建carthage update.以下是一些输出验证我目前正在使用Swift 2:
$ swift --version
Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31)
Target: x86_64-apple-macosx10.9
$ ls -lh $(which swift)
-rwxr-xr-x 1 root wheel 18K Jul 8 19:52 /usr/bin/swift
Run Code Online (Sandbox Code Playgroud)
现在我想切换到使用Swift 3进行构建.我安装了多个工具链/Library/Developer/Toolchains,这是OSX在运行安装程序时安装它们的地方:
$ ls -lh /Library/Developer/Toolchains
drwxr-xr-x 6 root wheel 204B Sep 30 20:07 …Run Code Online (Sandbox Code Playgroud) 我已经四处寻找保存一般文本文件的位置以便阅读我的Android项目,但找不到明确的答案.当我将"foo.txt"文件保存到我的res/raw文件夹中时,有人建议(我必须创建原始文件夹),R.java文件会出现以下错误:
public static final class raw {
public static final int 1_1=0x7f050000;
}
Run Code Online (Sandbox Code Playgroud)
这是因为我的文件在第一行包含字符串"1_1",我想要它.文件夹结构中的哪个位置我应该把我的文件读出来?该文件不是由Android创建的,而是由我手动创建的.
有人也请告知如何以下列格式阅读文件?我希望能够逐个读取字符串和数字,并在我的Android项目中插入java变量.最好用逗号或空格分隔?
1_1
String
Int
Int String String Int Int Float Float Int Int
Int String String Int Int Float Float Int Int
Int String String Int Int Float Float Int Int
Int String String Int Int Float Float Int Int
Int String String Int Int Float Float Int Int
Int String String Int Int Float Float Int Int
Run Code Online (Sandbox Code Playgroud)
更新了更多代码:
package com.my.package;
import java.io.File;
import android.app.Activity;
import …Run Code Online (Sandbox Code Playgroud) 我想在bash中创建一个for循环,从1运行到存储在变量中的数字bash.我已经尝试过做这个问题的答案,但它产生了这个错误:
Syntax error: Bad for loop variable
Run Code Online (Sandbox Code Playgroud)
我的操作系统是Ubuntu 12.04,代码如下:
#!/bin/bash
TOP=10
for ((i=1; i<=$TOP; i++))
do
echo $i
done
Run Code Online (Sandbox Code Playgroud)
这个错误信息是什么意思?这是一个输出图像:

我试图读取从Microsoft Excel导出的csv文件,如下所示:
114.9;280.9;501.5;0;W10;Firewall south;A;1;2;;
119.0;280.9;501.5;0;W10;Southern escape route;B;2;3;asdasdf;
120.5;280.0;501.5;0;W10;Southern escape route;C;3;4;;
Run Code Online (Sandbox Code Playgroud)
分隔符是分号,有些列可能是空的.例如,可以填充列10 asdasdf作为示例.我的代码看起来像这样:
reader = csv.reader(open(inFile), delimiter=";")
nodesTable = window.getNodesTable()
pathsTable = window.getPathsTable()
clearTable(nodesTable)
clearTable(pathsTable)
for x, y, z, safe, mod, descr_node, name, start, end, descr_path in reader:
nodesTable.SetStringItem(counter, nodesTable_ID_x, x)
nodesTable.SetStringItem(counter, nodesTable_ID_y, y)
nodesTable.SetStringItem(counter, nodesTable_ID_z, z)
nodesTable.SetStringItem(counter, nodesTable_ID_SafeArea, safe)
nodesTable.SetStringItem(counter, nodesTable_ID_Module, mod)
nodesTable.SetStringItem(counter, nodesTable_ID_Description, descr_node)
pathsTable.SetStringItem(counter, pathsTable_ID_Name, name)
pathsTable.SetStringItem(counter, pathsTable_ID_StartNode, start)
pathsTable.SetStringItem(counter, pathsTable_ID_EndNode, end)
pathsTable.SetStringItem(counter, pathsTable_ID_Description, descr_path)
Run Code Online (Sandbox Code Playgroud)
我收到了错误ValueError: too many values to unpack.我在这做错了什么?