Getting started with AndroidLayoutsGradle for AndroidRecyclerView onClickListenersNavigationViewIntentJSON in Android with org.jsonAndroid StudioResourcesData Binding LibraryExceptionsGetting Calculated View DimensionsAsyncTaskSharedPreferencesEmulatorMaterial DesignLint WarningsServiceStoring Files in Internal & External StorageWebViewProject SDK versionsRecyclerViewGoogle Maps API v2 for AndroidPorterDuff Mode9-Patch ImagesAndroid NDKRecyclerView DecorationsCamera 2 APIViewPagerCardViewHttpURLConnectionSQLiteADB (Android Debug Bridge)ButterKnifeSupporting Screens With Different Resolutions, SizesGlideRetrofit2DialogACRAGreenDAOFormatting StringsNotificationsAlarmManagerFragmentsHandlerCreating Custom ViewsBroadcastReceiverActivitySnackbarRuntime Permissions in API-23 +Logging and using LogcatVectorDrawable and AnimatedVectorDrawableTools AttributesToastInterfacesAnimatorsLocationTheme, Style, AttributeThe Manifest FileParcelableMediaPlayerMultidex and the Dex Method LimitData Synchronization with Sync AdapterMenuInstant Run in Android StudioPicassoBluetooth and Bluetooth LE APIRoboGuiceMemory LeaksUniversal Image LoaderVolleyWidgetsDate and Time PickersIntegrate Google Sign InIn-app BillingFloatingActionButtonContentProviderDagger 2RealmUnit testing in Android with JUnitAndroid VersionsWi-Fi ConnectionsSensorManagerLocalization with resources in AndroidProgressBarCustom FontsVibrationGoogle Awareness APIsText to Speech(TTS)UI LifecycleSpinnerData Encryption/DecryptionTesting UI with EspressoWriting UI tests - AndroidGreenRobot EventBusOkHttpEnhancing Android Performance Using Icon FontsHandling Deep LinksCanvas drawing using SurfaceViewFirebaseCrash Reporting ToolsCheck Internet ConnectivityFacebook SDK for AndroidUnzip File in AndroidAndroid Places APICreating your own libraries for Android applicationsGsonDevice Display MetricsTextViewListViewBuilding Backwards Compatible AppsLoaderProGuard - Obfuscating and Shrinking your codeDetect Shake Event in AndroidTypedef Annotations: @IntDef, @StringDefCapturing ScreenshotsMVP ArchitectureOrientation ChangesXposedSecurityPackageManagerImageViewGesture DetectionDoze ModeAndroid Sound and MediaSearchViewCamera and GalleryCallback URLTwitter APIsDrawablesColorsConstraintLayoutRenderScriptFrescoSwipe to RefreshAutoCompleteTextViewInstalling apps with ADBIntentServiceAdMobImplicit IntentsPublish to Play StoreFirebase Realtime DataBaseImage CompressionEmail ValidationKeyboardButtonTextInputLayoutBottom SheetsCoordinatorLayout and BehaviorsEditTextAndroid Paypal Gateway IntegrationFirebase App IndexingFirebase Crash ReportingDisplaying Google AdsAndroid Vk SdkLocalized Date/Time in AndroidCount Down TimerBarcode and QR code readingOtto Event BusTransitionDrawablePort Mapping using Cling library in AndroidCreating Overlay (always-on-top) WindowsExoPlayerInter-app UI testing with UIAutomatorMediaSessionSpeech to Text ConversionFileProviderPublish .aar file to Apache Archiva with GradleXMPP register login and chat simple exampleAndroid AuthenticatorRecyclerView and LayoutManagersAudioManagerJob SchedulingAccounts and AccountManagerIntegrate OpenCV into Android StudioSplit Screen / Multi-Screen ActivitiesThreadMediaStoreTime UtilsTouch EventsFingerprint API in androidMVVM (Architecture)BottomNavigationViewORMLite in androidYoutube-APITabLayoutRetrofit2 with RxJavaDayNight Theme (AppCompat v23.2 / API 14+)ShortcutManagerLruCacheJenkins CI setup for Android ProjectsZip file in androidVector DrawablesfastlaneDefine step value (increment) for custom RangeSeekBarGetting started with OpenGL ES 2.0+Check Data ConnectionAndroid Java Native Interface (JNI)FileIO with AndroidPerformance OptimizationRobolectricMoshiStrict Mode Policy : A tool to catch the bug in the Compile Time.Internationalization and localization (I18N and L10N)Fast way to setup Retrolambda on an android project.How to use SparseArrayFirebase Cloud MessagingShared Element TransitionsAndroid ThingsVideoViewViewFlipperLibrary Dagger 2: Dependency Injection in ApplicationsFormatting phone numbers with pattern.How to store passwords securelyAndroid Kernel OptimizationPaintAudioTrackWhat is ProGuard? What is use in Android?Create Android Custom ROMsJava on AndroidPagination in RecyclerViewGenymotion for androidHandling touch and motion eventsCreating Splash screenConstraintSetCleverTapPublish a library to Maven Repositoriesadb shellPing ICMPAIDLAndroid programming with KotlinAutosizing TextViewsSign your Android App for ReleaseContextActivity RecognitionSecure SharedPreferencesSecure SharedPreferencesBitmap CacheAndroid-x86 in VirtualBoxJCodecDesign PatternsOkioGoogle signin integration on androidTensorFlowAndroid game developmentNotification Channel Android OBluetooth Low EnergyLeakcanaryAdding a FuseView to an Android ProjectAccessing SQLite databases using the ContentValues classEnhancing Alert DialogsHardware Button Events/Intents (PTT, LWP, etc.)SpannableStringLooperOptimized VideoViewGoogle Drive APIAnimated AlertDialog BoxAnnotation ProcessorSyncAdapter with periodically do sync of dataCreate Singleton Class for Toast MessageFastjsonAndroid Architecture ComponentsJacksonGoogle Play StoreLoading Bitmaps EffectivelyGetting system font names and using the fontsSmartcardConvert vietnamese string to english string Android

Android Studio

Other topics

Setup Android Studio

System Requirements

  • Microsoft® Windows® 8/7/Vista/2003 (32 or 64-bit).
  • Mac® OS X® 10.8.5 or higher, up to 10.9 (Mavericks)
  • GNOME or KDE desktop

Installation

Window

  1. Download and install JDK (Java Development Kit) version 8
  2. Download Android Studio
  3. Launch Android Studio.exe then mention JDK path and download the latest SDK

Linux

  1. Download and install JDK (Java Development Kit) version 8
  2. Download Android Studio
  3. Extract the zip file
  4. Open terminal, cd to the extracted folder, cd to bin (example cd android-studio/bin)
  5. Run ./studio.sh

Filter logs from UI

Android logs can be filtered directly from the UI. Using this code

public class MainActivity extends AppCompatActivity {
    private final static String TAG1 = MainActivity.class.getSimpleName();
    private final static String TAG2 = MainActivity.class.getCanonicalName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.e(TAG1,"Log from onCreate method with TAG1");
        Log.i(TAG2,"Log from onCreate method with TAG2");
    }
}

If I use the regex TAG1|TAG2 and the level verbose I get

01-14 10:34:46.961 12880-12880/android.doc.so.thiebaudthomas.sodocandroid E/MainActivity: Log from onCreate method with TAG1
01-14 10:34:46.961 12880-12880/android.doc.so.thiebaudthomas.sodocandroid I/androdi.doc.so.thiebaudthomas.sodocandroid.MainActivity: Log from onCreate method with TAG2

enter image description here

The level can be set to get logs with given level and above. For example the verbose level will catch verbose, debug, info, warn, error and assert logs.

Using the same example, if I set the level to error, I only get

01-14 10:34:46.961 12880-12880/androdi.doc.so.thiebaudthomas.sodocandroid E/MainActivity: Log from onCreate method with TAG1

enter image description here

Create filters configuration

Custom filters can be set and save from the UI. In the AndroidMonitor tab, click on the right dropdown (must contains Show only selected application or No filters) and select Edit filter configuration.

Enter the filter you want

enter image description here

And use it (you can selected it from the same dropdown)

enter image description here

Important If you add an input in the filter bar, android studio will consider both your filter and your input.

With both input and filter there is no output Custom filter with input

Without filter, there is some outputs Filter input only

Custom colors of logcat message based on message importance

Go to File -> Settings -> Editor -> Colors & Fonts -> Android Logcat

Change the colors as you need:

enter image description here

Choose the appropriate color:

enter image description here

Enable/Disable blank line copy

ctrl + alt + shift + / (cmd + alt + shift + / on MacOS) should show you the following dialog:

enter image description here

Clicking on Registry you will get

enter image description here

The key you want to enable/disable is

editor.skip.copy.and.cut.for.empty.selection

Tested on Linux Ubuntu and MacOS.

Android Studio useful shortcuts

The following are some of the more common/useful shortcuts.

These are based on the default IntelliJ shortcut map. You can switch to other common IDE shortcut maps via File -> Settings -> Keymap -> <Choose Eclipse/Visual Studio/etc from Keymaps dropdown>

ActionShortcut
Format codeCTRL + ALT + L
Add unimplemented methodsCTRL + I
Show logcatALT + 6
BuildCTRL + F9
Build and RunCTRL + F10
FindCTRL + F
Find in projectCTRL+SHIFT + F
Find and replaceCTRL + R
Find and replace in projectCTRL + SHIFT + R
Override methodsCTRL + O
Show projectALT + 1
Hide project - logcatSHIFT + ESC
Collapse allCTRL + SHIFT + NumPad +
View Debug PointsCTRL + SHIFT + F8
Expand allCTRL + SHIFT + NumPad -
Open SettingsALT + s
Select Target (open current file in Project view)ALT + F1ENTER
Search EverywhereSHIFTSHIFT (Double shift)
Code | Surround WithCTRLALT + T
Create method form selected codeALT + CTRL

Refactor:

ActionShortcut
Refactor This (menu/picker for all applicable refactor actions of the current element)Mac CTRL + T - Win/Linux CTRL + ALT + T
RenameSHIFT + F6
Extract MethodMac CMD + ALT + M - Win/Linux CTRL + ALT + M
Extract ParameterMac CMD + ALT + P - Win/Linux CTRL + ALT + P
Extract VariableMac CMD + ALT + V - Win/Linux CTRL + ALT + V

Android Studio Improve performance tip

Enable Offline Work:

  1. Click File -> Settings. Search for "gradle" and click in Offline work box.
  2. Go to Compiler (in same settings dialog just below Gradle) and add --offline to Command-line Options text box.

Improve Gradle Performance

Add following two line of code in your gradle.properties file.

org.gradle.daemon=true
org.gradle.parallel=true

Increasing the value of -Xmx and -Xms in studio.vmoptions file

-Xms1024m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=256m
-XX:+UseCompressedOops

Window

%USERPROFILE%.{FOLDER_NAME}\studio.exe.vmoptions and/or %USERPROFILE%.{FOLDER_NAME}\studio64.exe.vmoptions

Mac

~/Library/Preferences/{FOLDER_NAME}/studio.vmoptions

Linux

~/.{FOLDER_NAME}/studio.vmoptions and/or ~/.{FOLDER_NAME}/studio64.vmoptions

View And Add Shortcuts in Android Studio

By going to Settings >> Keymap A window will popup showing All the Editor Actions with the their name and shortcuts. Some of the Editor Actions do not have shortcuts. So right click on that and add a new shortcut to that.
Check the image below

enter image description here

Gradle build project takes forever

Android Studio -> Preferences -> Gradle -> Tick Offline work and then restart your Android studio.

Reference screenshot:

enter image description here

Create assets folder

  • Right click in MAIN folder > New > Folder > Assets Folder.
  • Assets folder will be under MAIN folder with the same symbol as RES folder.
  • In this example I put a font file. enter image description here

Contributors

Topic Id: 107

Example Ids: 16393,430,431,9317,10554,16391,16392,16610,21517,29378

This site is not affiliated with any of the contributors.