- Cordova splash screen size classes.
any any
is a square.com any
is portrait.any com
is landscape. Want to guess whatcom com
is? It's "landscape (narrow)". - The answer to hiding secrets in Android apps is: it is impossible.
- You can view secure content on your secondary display if you say it is secure.
- There is a special "pinterest mode" for RecyclerView, called StaggeredGridLayoutManager.
- Streamed install (with
cmd package
) installs an APK without having adb save the file somewhere on the device first, whichpm
used to do. - Being confusing is recommended.
- Before you truly understand what it is,
Fragment
is already deprecated. Fragments may have been the separate panes in tablet mode, for example. Layouts can contain Fragments. - Webview session storage available was unlimited for Android versions 4.1 and 4.3, but not 4.2 and 4.4, which had 10MB.
- Your package id must have at least one dot in it, so it can't be
com
. JobIntentService
. A "job intent service" whose "job" is to "serve job intents". Or does it "serve intent jobs"? Or "job service intents"? Oh well. But after all that, what does it enque? "Work".JobIntentService.enqueueWork()
.- You may track if a specific user uninstalls your app by setting up a silent push notification (or alarm, or scheduled task) that asks the app to ping your own server with your (semi-unique) Google advertising ID. When your app no longer pings back, the user uninstalled your app.
- "If you target Android 8.0 (API level 26) and post a notification without specifying a notification channel, the notification does not appear and the system logs an error."
minSdkVersion=x
prevents the APK from being installed on anything less than.targetSdkVersion=x
disables extra compatibility code that is run to keep the APK compatible with version x.- Android Studio 0.80 beta is, by default, broken.
- Handling menu clicks is as stupid as you want it to be, but here is a simpler one
- For whatever reason, it is impossible to set a negative value on a NumberPicker. You can only subtract the value by a negative number after the fact.
- Do know what these mean: activity/fragment lifecycles, device rotation, services, broadcasts, background tasks, asynchronous tasks, views, adapters, recyclerview, "view holder pattern"
- Strings are put inside
project_root/app/src/main/res/values/strings.xml
, because nested folders are the best. - The plus thing in the XML, like
android:id="@+id/edit_message"
, is required only for the line that defines it. android:hint
are placeholder texts.layout_weight
is a relative number. Alayout_weight
of 1 means 100% of the width IF the control happens to be the only control inside aLinearView
with the weight specified. If two controls have the weight specified (say 1, 1), then each control shares 50% of the width.- If
layout_weight
is given, thenlayout_width
is useless (irrelevant), and should be set to 0dp or 0px. - The back button does "back navigation" (whichever activity shown in reverse chronological order); the in-app backs do "up navigation". The term "up" refers to the hierarchical parent of the current activity, a hierarchy you declare in
AndroidManifest.xml
. - Putting a library into
libs/
seems to do it. - There are project (
./build.gradle
) and app-level (./app/build.gradle
) gradle files. The former defines dependencies, and the latter uses them. - If gradle is too old, update the
classpath 'com.android.tools.build:gradle:2.1.2'
... in the gradle file. Gradle will update itself. True fact. - Order in the layout xml files matters.
- The project's JDK settings is in File > Project Structure, which is not in Settings for studio.
- If you don't know what fresh hell you are doing, here is a layouts cheat sheet.
- Accessing the Internet on the main thread, get this, raises the
NetworkOnMainThreadException
. - AsyncTask takes just one type of parameter, but you can use "the setter" (?) to use additional types, or simply pass in an
Object
and re-cast from there. - "The difference between Handler and AsyncTask is: Use AsyncTask when Caller thread is a UI Thread."
- It is near impossible to conjure a popup from a non-activity class.
(an AsyncTask).get()
immediately gets the value from its execute(). Then again, that is a synchronous move.Activity
apparently extendsContext
.Application
also extendsContext
.- Find your dependency versions on this website. It only searches on mavenCentral, I think.
- Two-way binding is not natively supported by the designer thing, but there are lots of one-way binding libraries available.
- To use that
com.android.databinding
plugin, the layout file must have<Layout>
as the root, not anything else, like<LinearLayout>
. - Java 8 must be explicitly enabled
- The superclass of your activity has a
setTitle()
that does what you think it does. - Loser answered the wrong base64 question, but it works. This should work.
- Two apps signed with the same key can securely share code and data.
- adbd cannot run as root in production builds.
- The default support library already supports automatic day/night theming. You just need to specify
AppCompatDelegate.MODE_NIGHT_AUTO
and it will be themed for you. - Burak says
Serializable
is a form of reflection, and has poor performance. - In some cases,
onDestroy
is never called when an activity is destroyed. - Sometimes you might want to check if you can run code based on the SDK version with which your app is built (like
Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2
). Actually, I don't think you'll ever need to do that. - try-with-resources is only supported if your minSdkVersion is set to 19 or higher. It looks like
try (foo = new SomeResourceLikeAFile()) { foo... }
. Multiple resources can be tried by separating with a;
. startActivity
accepts anIntent
rather thanActivity
because reasons.- If even one of your neurons fire up, you would have noticed that
new Intent(CurrentActivity.this, ...)
andnew Intent(this, ...)
are identical statements. - IDs are under_scored. Variables are camelCased, As always, because reasons.
- It is possible to name your package using someone else's domain, like
com.microsoft.lol
. - "Target SDK version" is the level at which you can use the SDK's features. ["Min SDK version"][stackoverflow 14] is the level at which you, the developer, have made sure the app still works by handling missing features properly.
- The API level of a pre-release version of Android is not a number. For P preview, the API level is just "P".
- The
R
class is a public static final class that only contains resource-related attributes for your code to use. Drawable
can be lots of things. PNG, JPG, GIF, XML... unfornately none of those XML formats are SVG.- You can create a vector asset inside
File -> New -> Vector Asset
. - Whether your activity has a certain theme doesn't get set in your layout xml (
res/layout/*.xml
), but inAndroidManifest.xml
, because FUCK you. - You can display a downloaded image without first saving it somewhere.
- "
@aar
is Gradle's "Artifact only" notation that excludes dependencies by default." setContentView(R.layout.main)
controls which activity shows which layout. In this case, it showsres/layout/main.xml
. You call it insideonCreate
usually. Interestingly, that "view" can also be a button.- A notification has no actions by default. To have it, say, bring the app back up, you need to give it an intent that's equivalent to one where the user tapped on the icon from the launcher, and then
setContentIntent
to the builder. - When the docs say a method "is deprecated", it doesn't necessarily mean all methods with that name are deprecated. It just means a method with that name and signature is deprecated.
- The fused location provider is part of google play services.
- If you are absolutely sure that you requested a permission using the
<uses-permission android:name="android.permission.INTERNET "/>
tag, but it isn't working for some reason, notice there should be no space after the wordINTERNET
. Idiot. - The "builder" pattern appears to create new objects, whose instances have successively more attributes added (hence "building"), and the final
build()
command returns the thing you have been trying to build all along. This allows a developer to call flexible methods in a strict language like Java, without overloading a method with a different number of parameters. - The
m
ands
variable prefixes actually only concern apps that are to be contributed to the AOSP project, and should not be used in your personal projects. - You can catch fatal exceptions (they are
Throwable
s), but they should only be caught at the topmost layer. - A
SharedPreferences
lets yougetString()
, but it doesn't let youputString()
. Classic Android. You need to get the prefs' "editor" throughprefs.edit()
, which then has aputString()
. - Android Go editions may have unexpected restrictions, such as launching an activity from a service using the
SYSTEM_ALERT_WINDOW
permission. - Apparently if your device supports P, it can potentially just boot off an image called the generic system image (GSI). YMMV.
- You need 100GB of disk space to compile LineageOS once.
- You define the app's icon in
AndroidManifest.xml
->manifest[application:icon]
. That@mipmap/ic_launcher
corresponds to anic_launcher.xml
, which has<adaptive-icon>
inside. - Apps can export a service. With
android:exported="true"
, a service can be invoked by another application. Without that, an app can have a service but other applications cannot see it (unless you use MyAndroidTools or something). android.*
packages (are supposed to) come with the system, whileandroidx.*
packages come with the app.- Displaying a button over something else is surprisingly difficult without absolute positioning or z-index.
- You cannot have a string reference another one like
<string name="string_default">@string/string1 TEST</string>
, but entire substitutions like<string name="string_default">@string/string1</string>
are fine. - To make a scrollable
ConstraintLayout
, really put aScrollView
outside theConstraintLayout
. xmlns:tools="http://schemas.android.com/tools"
means everytools:abc
uses that schema, and that is the namespace in this element. There is no need to redeclare it in children elements.RecyclerView
s were created because layout inflation (turning XML into whatever) is such a costly operation that Android would rather not do that for the same type of content.- Use
getResources().getString(R.string.MY_STRING)
to load a string in your class. If your class is not an instance ofContext
(for example, not anActivity
), you don't get that method. - To build an Android app with no interface, and have Android Studio not complain about "Default Activity not found", go to "Edit Configurations" and have it launch "Nothing".
tools:context
is only used by the UI editor when rendering the preview, for things that require knowledge coming from the activity. Omitting it does not impact your app running.findViewById
is one way to work with your activity files, but if you are using Kotlin, there is an extension calledkotlinx.android.synthetic
that lets you auto-import these items. People say it's no longer best practice though, so look up view binding, some official practice.- XML (layout) filenames cannot have capital letters.
- Java and Kotlin start their programs at the
main
function. Except for Android apps. There is nomain
for you to define there because the runtime decides which function to call based on what you put in the manifest, none of which you have control over. - Turns out
val name: String by helloViewModel.name.observeAsState("")
is syntactic sugar forval nameState: State<String> = helloViewModel.name.observeAsState("")
. Note that the variable is nownameState
instead ofname
. - Retrofit2 is a type-safe http client. If you don't own your server and can't guarantee its return value, use okhttp instead.