RecycleView
RecyclerView.Adapter<T extends BaseAdapter>
RecyclerView.ViewHolder<T extends BaseViewHolder>
LinearLayoutManager
RecycleView
RecyclerView.Adapter
RecyclerView.ViewHolder<T extends BaseViewHolder>
LinearLayoutManager
RecycleView
RecyclerView.Adapter
RecyclerView.ViewHolder
LinearLayoutManager
RecycleView
RecyclerView.Adapter<VH extends ViewHolder>
RecyclerView.ViewHolder
LinearLayoutManager
Intent(this, NextActivity::class.java).also { intent ->
startActivity(intent)
}
Intent(this, NextActivity::class.java).apply {
put(EXTRA_NEXT, "some data")
}.also { intent ->
activityStart(intent)
}
Intent(this, NextActivity::class.java).apply {
putExtra(EXTRA_NEXT, "some data")
}.also { intent ->
startActivity(intent)
}
Intent(this, NextActivity::class.java).apply {
put(EXTRA_NEXT, "some data")
}.also { intent ->
activityStart(intent)
}
in build.gradle:include ':app',':about' ':settings'in settings.gradle:include ':app',':about' ':settings'in settings.gradle:include ':about',':settings'in gradle.properties:include ':app',':about' ':settings' defaultConfig {
...
minApiVersion 21
targetApiVersion 28
}
defaultConfig {
...
targetSdkVersion 21
testSdkVersion 28
}
defaultConfig {
...
minSdkVersion 21
testApiVersion 28
}
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
}
private lateinit var textView: TextView
override fun onCreateView(...): View? {
val root = inflator.inflator(R>layout.fragment_home, container, false)
textView = ??
return root
}
Hinweis: AndroidJUnitRunner ermöglicht es uns, JUnit3/4-Stil-Tests auf Android-Geräten auszuführen
Erklärung: In der Methode "getDefaultSharedPrefarances(this).getString()" wird der zweite Parameter übergeben, damit er zurückgegeben werden kann, falls der Schlüssel nicht existiert. Wir müssen also einen leeren String übergeben, der zurückgegeben wird, falls der Schlüssel nicht existiert.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="4dp"
android:color="@android:color/white" />
<solid android:color="@android:color/black" />
</shape>
<oval xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="4dp" android:color="@android:color/black"/>
<solid android:color="@android:color/white"/>
</oval>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="4dp"
android:color="@android:color/black" />
<solid android:color="@android:color/white" />
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="4dp"
android:color="@android:color/white" />
<solid android:color="@android:color/white" />
</shape>
<merge/><include/><layout/><add/>android.permission.ACCESS_NETWORK_STATE
LinearLayout? <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>




val dialerIntent = Intent()
val et = findViewById(R.id.some_edit_text)
dialerIntent.action = Intent.ACTION_DIAL
dialerIntent.data = Uri.parse("tel:" + et.getText()?.toString())
startActivity(dialerIntent)
startActivityWithResult() sollte anstelle von startActivity() verwendet werden, wenn Intent.ACTION_DIAL verwendet wird.Intent.ACTION_DIAL muss die Intent-Option Intent.FLAG_ACTIVITY_NEW_TASK hinzugefügt werden, wenn dieser dialerIntent verwendet wird.dialerIntent wird eine ActivityNotFoundException auf Geräten auslösen, die Intent.ACTION_DIAL nicht unterstützen.android.permission.CALL_PHONE muss zuerst angefordert werden, bevor Intent.ACTION_DIAL verwendet werden kann./assets-Verzeichnis speichern?Ressourcen-ID benötigen, wie R.assets.filenameResources.openRawResource()Intent, anstatt die Kamera-Berechtigung direkt anzufordern?Intent verarbeitet, wird Ihre Designentscheidungen respektieren.Intent verarbeitet, stellt die Benutzeroberfläche bereit.ActivityCompat.shouldShowRequestPermissionRationale() verwenden?release-Builds aktivieren. Wie können Sie ein neues Feld in der generierten BuildConfig-Klasse erstellen, um diesen Wert zu speichern?buildTypes {
debug {
buildConfig 'boolean', 'ENABLE_ANALYTICS', 'false'
}
release {
buildConfig 'boolean', 'ENABLE_ANALYTICS', 'true'
}
}
buildTypes {
debug {
buildConfig 'String', 'ENABLE_ANALYTICS', 'false'
}
release {
buildConfig 'String', 'ENABLE_ANALYTICS', 'true'
}
}
buildTypes {
debug {
buildConfigField 'boolean', 'ENABLE_ANALYTICS', 'false'
}
release {
buildConfigField 'boolean', 'ENABLE_ANALYTICS', 'true'
}
}
buildTypes {
debug {
buildConfigField 'boolean', 'ENABLE_ANALYTICS', 'true'
}
release {
buildConfigField 'boolean', 'ENABLE_ANALYTICS', 'false'
}
}
ProGuard -keepclassmembers zu den betreffenden Netzwerkdatenübertragungsobjekten (DTOs) hinzugefügt wurden@SerializedName auf seine Member-Eigenschaften angewendet hat
<androidx.constraintlayout.widget.ConstraintLayout
...>
<TextView
android:id="@+id/text_dashboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:padding="8dp"
android:textAlignment="center"
android:text="Dashboard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
...>
<TextView
android:id="@+id/text_dashboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:text="Dashboard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
...>
<TextView
android:id="@+id/text_dashboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:padding="8dp"
android:textAlignment="center"
android:text="Dashboard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
...>
<TextView
android:id="@+id/text_dashboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:padding="8dp"
android:text="Dashboard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Intent auf Ihre Activity-Klasse zugreifen? <activity android:name=".ExampleActivity" />
<activity android:name=".ExampleActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
</intent-filter>
</activity>
<activity android:name=".ExampleActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ExampleActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
Erklärung: Intent-Filter werden verwendet, um Activities für andere Apps über Intents zugänglich zu machen. Wir müssen also die Option ohne Intent-Filter wählen, um sicherzustellen, dass sie nicht per Intent zugänglich ist
ActivityManager.isLowRamDevice(), um herauszufinden, ob ein Gerät sich selbst als “Low RAM” definiert.Activity.islowRam(), um herauszufinden, ob ein Gerät sich selbst als “Low RAM” definiert.ConnectivityManager.hasLowMemory(), um herauszufinden, ob ein Gerät sich selbst als “Low RAM” definiert.<include/>, um sie in andere Layout-XML-Dateien einzubinden.
<shape xmlns:android-"http://schemas.android.com/apk/res/android"
android:shape-"oval">
<gradient
android:startColor-"@android:color/white"
android:endColor-"@android:color/black"
android:angle-"45"/>
</shape>
<rectangle xmlns:android-"http://schemas.android.com/apk/res/android">
<gradient
android:startColor-"@android:color/white"
android:endColor-"android:color/black"
android:angle-"135"/>
</rectangle>
<shape xmlns:android-"http://schemas.android.com/apk/res/android"
android:shape-"rectangle">
<gradient
android:startColor-"@android:color/white"
android:endColor-"@android:color/black"
android:angle-"135"/>
</shape>
<shape xmlns:android-"http://schemas.android.com/apk/res/android"
android:shape-"rectangle">
<gradient
android:startColor-"@android:color/white"
android:endColor-"@android:color/black"
android:angle-"98"/>
</shape>

android {
...
defaultConfig{...}
buildTypes{
debug{...}
releasae{...}
}
flavorDimensions "environment"
productFlavors {
producation {...}
staging {...}
}
}
Conversion to Dalvik format filed: Unable to execute dex: method ID not in [0, 0xffff]: 65536
<?xml version=1.0 encoding="utf-8"?>
<resources>
<dimen name="spacing_medium">8dp</dimen>
<dimen name="spacing_large">12dp</dimen>
</resources>
<ImageView
android:id=@+id/image_map_pin"
android:layout_width="wrap_content"
android:layout_heignt="wrap_content"
android:src=@drawable/map_pin />
<ImageView
android:id=@+id/image_map_pin"
android:layout_width="wrap_content"
android:layout_heignt="wrap_content"
androi:layout_botttom="@dimen/spacing_medium"
android:src=@drawable/map_pin />
<ImageView
android:id=@+id/image_map_pin"
android:layout_width="wrap_content"
android:layout_heignt="wrap_content"
android:layout_marginBottom="@resources/spacing_medium"
android:src=@drawable/map_pin />
<ImageView
android:id=@+id/image_map_pin"
android:layout_width="wrap_content"
android:layout_heignt="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:src=@drawable/map_pin />
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_post_create)
if (savedInstanceState != null) return
val fragment = CreatePostFragment()
supportFragmentManager
.beginTransaction()
.add(R.id. fragment_container, fragment)
.commit()
}
Intent(this, AboutActivity::class).also { intent -> startService(intent)}Intent(this, AboutActivity::class.java).also { intent -> startActivity(intent)}Intent(this, AboutActivity::class).also { intent -> activity(intent)}Intent(this, AboutActivity::class).also { intent -> startActivity(intent)}Erklärung: Intent(Context packageContext, Class<?> cls) Hinweis: Class nicht KClass
Erklärung: Wenn Sie Ihr Projekt mit Android Gradle Plugin 3.4.0 oder höher erstellen, verwendet das Plugin nicht mehr ProGuard zur Durchführung der Code-Optimierung zur Kompilierzeit. Stattdessen arbeitet das Plugin mit dem R8-Compiler
A

B

C

D

BuildConfigBuildInfoConfigParamsConfigInfo <androidx.constraintlayout.widget.ConstrantLayout
...>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstrantLayout>
Der Button hat keine GrößeDer Button ist nicht am Ende des übergeordneten Containers beschränktButtons können nicht über ihre Standardgröße hinaus erweitert werdenDer Button sollte seine Höhe ebenfalls auf 0dp setzenVerwaltung von SystemdienstenVerarbeitung von BenutzereingabeereignissenLaden von Daten aus dem Internet oder einer lokalen DatenquelleDurchführung von Bitmap-TransformationenStringTextString-arrayPluralsonPause()onResume()onOpen()onStart() fun showCamera(view: View) {
Log.i(TAG, "Show camera button pressed.")
if (ContextCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.CAMERA) {
showCameraPreview()
}
else {
requestPermissionLauncher.launch(Manifest.permission.CAMERA)
}
}
fun showCamera(view: View) {
Log.i(TAG, "Show camera button pressed.")
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED) {
showCameraPreview()
}
else {
requestPermissionLauncher.launch(Manifest.permission.CAMERA)
}
}
fun showCamera(view: View) {
Log.i(TAG, "Show camera button pressed.")
showCameraPreview()
}
fun showCamera(view: View) {
Log.i(TAG, "Show camera button pressed.")
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
showCameraPreview()
}
else {
requestPermissionLauncher.launch(Manifest.permission.CAMERA)
}
}
<string name="upload_photo_notification">%1$d von %2$d Fotos hochgeladen</string>
val string: String = getString(
R.string.upload_photo_notification,
"2",
"5"
)
val string: String = getString(
R.id.upload_photo_notification,
2,
5
)
val string: String = getString(
R.string.upload_photo_notification,
2,
5
)
val string: String = getString(
R.id.upload_photo_notification,
"2",
"5"
)
"Sie haben 1 Tag verbleibend"
"Sie haben 2 Tage verbleibend"
<string name="trial_days_left_one"> Sie haben %1$d Tag verbleibend</string>
<string name="trial_days_left_other">Sie haben %1$d Tage verbleibend</string>
<plurals name="trial days left">
<plural quantity="one">Sie haben %1$d Tag verbleibend</plural>
<plural quantity="other">Sie haben %1$d Tage verbleibend</plural>
</plurals>
<plurals name="trial_days_left">
<item quantity="one">Sie haben %1$d Tag verbleibend</item>
<item quantity="other">Sie haben %1$d Tage verbleibend</item>
</plurals>
<string name="trial_days_left">
<plural quantity="one">Sie haben %1$d Tag verbleibend</plural>
<plural quantity="other">Sie haben &1$d Tage verbleibend</plural>
</string>
wenn die App deinstalliert wirdwenn die App in den Hintergrund gelegt wirdwenn das Gerät im Akku-Optimierungsmodus istwenn Netzwerkanfragen im Haupt-Thread durchgeführt werden
recyclerView.setLayoutManager(GridLayoutManager(this, 3))
val coulumnCount = resources.getInteger(R.integer.column_count)
recyclerView.setLayoutManager(GridLayoutManager(this, columnCount))
recyclerView.setLayoutManager(LinearLayoutManager(this))
val coulumnCount = resources.getInteger(R.integer.column_count)
recyclerView.setLayoutManager(LinearLayoutManager(this, columnCount))
Intent, anstatt die Kamera-Berechtigung direkt anzufordern?Intent verarbeitet, wird Ihre Designentscheidungen respektieren.Intent verarbeitet, stellt die Benutzeroberfläche bereit.