//定义个程序名的字符串,位于res/ values/strings.xml文件
<resources>
<string name="app_name">HelloWorld</string>
</resources>
代码中通过
R.string.app_name
XML中通过
@string/app_name
//外层中build.gradle文件
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:3.5.0‘
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
//内层build.gradle文件
apply plugin: ‘com.android.application‘
android {
compileSdkVersion 29//指定项目编译版本
buildToolsVersion "29.0.2"//指定项目构建版本
defaultConfig {
applicationId "com.example.testapplication"//指定项目包名
minSdkVersion 15//最低兼容版本
targetSdkVersion 29//已在该版本做过详细测试
versionCode 1//指定项目版本号
versionName "1.0"//指定项目版本名
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {//指定生成的安装文件配置
release {
minifyEnabled false//是否进行代码混淆
proguardFiles getDefaultProguardFile(‘proguard-android-optimize.
txt‘), ‘proguard-rules.pro‘//混淆时的规则文件
}
}
}
dependencies {//指定项目的依赖关系
//声明本地依赖 libs下的所有jar添加到项目
implementation fileTree(dir: ‘libs‘, include: [‘*.jar‘])
//声明远程依赖包
implementation ‘androidx.appcompat:appcompat:1.0.2‘
implementation ‘androidx.constraintlayout:constraintlayout:1.1.3‘
//声明测试库
testImplementation ‘junit:junit:4.12‘
androidTestImplementation ‘androidx.test:runner:1.2.0‘
androidTestImplementation ‘androidx.test.espresso:espresso-core:3.2.0‘
}
//举例
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
switch (requestCode){
case 1 :
if(resultCode == RESULT_OK){
String returnData = data.getStringExtra("data_return");
Log.d("MainActivity",returnData);
}
break;
default:
}
}
原文:https://www.cnblogs.com/nsss/p/11430495.html