\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{thecontinentalreaper (thecontinentalreaper)} \pdfinfo{ /Title (android-studio-app-development-cheat-sheet.pdf) /Creator (Cheatography) /Author (thecontinentalreaper (thecontinentalreaper)) /Subject (Android Studio App Development Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Android Studio App Development Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{thecontinentalreaper (thecontinentalreaper)} via \textcolor{DarkBackground}{\uline{cheatography.com/171910/cs/36123/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}thecontinentalreaper (thecontinentalreaper) \\ \uline{cheatography.com/thecontinentalreaper} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 15th December, 2022.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Mobile App Development Lifecycle}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Inception}} \textgreater{} {\bf{Design}}(UX-\textgreater{}UI) \textgreater{} {\bf{Development}} \textgreater{} {\bf{Stabilization }} \textgreater{} {\bf{Distribution}}} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{IDEs for Mobile App Development}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Android Studio (Java/Kotilin), XCode (Objective C/Swift, can only run on MacOS), Microsoft XNA (C\#, for Windows Phone apps), cocos2d(multi-language and platform, for games), Unity (C\#, cross-platform), React Native (JS, cross-platform), Flutter (Dart language), Apache Cordova (HTML5, CSS3 and JS, cross-platform), MiniProgram (for making lightweight apps that don't require installation and occupy little memory/space)} \tn % Row Count 9 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Design Patterns}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/thecontinentalreaper_1671073307_Screenshot from 2022-12-15 11-01-30.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{UI Design}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Principles}}: User familiarity, consistency, minimal surprise, recoverability, user guidance, user diversity} \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{UI Design Process}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/thecontinentalreaper_1671074024_Screenshot from 2022-12-15 11-12-39.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Broadcasts}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Broadcasts are messages sent whenever an event of interests occurs from the Android System or from apps. Apps can register to receive certain broadcasts. They must be defined programatically in the code in addition to being declared in the manifest with intent filters. `\textless{}intent-filter\textgreater{}\textless{}action android:name="ACTION"/\textgreater{}\textless{}/intent-filter\textgreater{}` BroadcastReceivers have an onReceive() function to check intent.action.% Row Count 9 (+ 9) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Server Connection}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Must include the following permissions}}: \newline % Row Count 1 (+ 1) `\textless{}uses-permission \seqsplit{android:name="android.permission.INTERNET"} /\textgreater{} \textless{}uses-permission \seqsplit{android:name="android.permission.ACCESS\_NETWORK\_STATE"} /\textgreater{}` \newline % Row Count 4 (+ 3) {\bf{WebView}} is a View that can be display web pages in your app.% Row Count 6 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Java vs Kotilin}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Functions}}\{\{nl\}\}`public fun sum(a: Int, b: Int): Int \{ return a + b \}` & {\bf{Variables}}\{\{nl\}\}`//val is immutable. var is mutable//\{\{nl\}\} val a: Int = 1 val b: String = "tim"\{nl\} //Types Int, String are optional and can be excluded//` \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} {\bf{ Nullable variable }} `\{\{nl\}\} var str S2? = "hku" \{\{nl\}\} str = null \{\{nl\}\}` {\bf{Null safety}} \{\{nl\}\} `var str: S2? = "hku" \{\{nl\}\} val I = S2?.length //if S2 is null, I is set o null` & {\bf{Arrays}} \{\{nl\}\}`val num = arrayOf(1, 2, 3, 4) //implicit type declaration \{\{nl\}\} val num = arrayOf\textless{}Int\textgreater{}(1, 2, 3, 4) //explicit type declaration\{\{nl\}\}for (i in 0..num.size-1) \{ print(num{[}i{]}) \}` \tn % Row Count 19 (+ 10) % Row 2 \SetRowColor{LightBackground} {\bf{Classes}}\{\{nl\}\}`class Person(val name: String, val age: Int? = null) //Declares class and constructor in one line!\{\{nl\}\}val person1 = Person("Sam", 20) //No new keyword` & {\bf{UI Elements}}\{\{nl\}\}`val edit\_text1 = findViewById\textless{}View\textgreater{}(R.id.editText1) as EditText\{\{nl\}\}val button1 = findViewById\textless{}View\textgreater{}(R.id.button1) as Button\{\{nl\}\}val listener = \seqsplit{View.OnClickListener} \{edit\_text1.setText("hello!")\}\{\{nl\}\}button1.setOnClickListener(listener)` \tn % Row Count 33 (+ 14) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Android Layout}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Inflate the layout file in OnCreate():}} \newline % Row Count 1 (+ 1) `public void onCreate(Bundle savedInstanceState) \{ \seqsplit{super.onCreate(savedInstanceState);} setContentView(R.layout.activity\_main);\}` \newline % Row Count 4 (+ 3) {\bf{FrameLayout}}: Display a single item at a time. All elements are positioned based on top left of the screen, and multiple elements will overlap. \newline % Row Count 7 (+ 3) {\bf{LinearLayout}}: Organizes elements along a single line, either horizontal or vertical (defined in XML property \seqsplit{`android:orientation="horizontal"`)} \newline % Row Count 10 (+ 3) {\bf{RelativeLayout}}: \seqsplit{`android:layout\_above/below/toLeftOf/toRightOf`} \{\{nl\}\} \seqsplit{`android:layout\_alignBaseline/Bottom/Left/Right/Top`} \newline % Row Count 13 (+ 3) {\bf{TableLayout}}:`\textless{}TableLayout\textgreater{}\textless{}TableRow\textgreater{}\textless{}Element android:layout\_column="1"/\textgreater{}\textless{}/TableRow\textgreater{}...\textless{}/TableLayout\textgreater{}` \newline % Row Count 16 (+ 3) {\bf{ConstraintLayout}}: Constrain a component to be in a position relative to another element. For example, `app:layout\_constraintLeft\_toRightOf="@+id/element"/\textgreater{}` would constrain the left side of the target to the right side of the other element. Rember, it is {\bf{app:layout}}, NOT {\bf{android:layout}}. \newline % Row Count 22 (+ 6) Use sp for font size, as it scales with user font preferences, and dp for others as it changes based on different screen density.% Row Count 25 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Concurrency}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{A process is an instance of a program that is being executed or processed. They don't share resources. Switching between process is expensive. Threads are segments of processes and share memory. {\bf{Thread\{...\}.start()}} \newline % Row Count 5 (+ 5) {\bf{Main Thread}} is the UI thread which renders everything onscreen. Two rules of Android UI: {\bf{Do not block the UI thread. Do not access the UI toolkit from outside the UI thread.}} \newline % Row Count 9 (+ 4) {\bf{Runnable}} is a class that can be run inside a Thread with just 1 method: run(). Remember to use {\bf{myUIElement.post\{ Runnable \}}} to force the Runnable object to join a queue so as to not break the rule. Handlers can also be used to update the UI thread (`handler.post\{ Runnable \}`). Remember, {\bf{Threads cannot update UI, only Handlers}}. Before running post() using Handler, call \seqsplit{handler.removeCallbacks(runnable)} to remove any pending posts of the runnable in the queue so as to avoid repeated task. {\bf{handler.postDelayed(runnable, time)}} delays the runnable from starting until after the specified time.% Row Count 22 (+ 13) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Activity LifeCycle}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/thecontinentalreaper_1671077226_Screenshot from 2022-12-15 12-06-14.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Intents and Filters}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Intents are messages sent between Activity, Service and Broad Receivers. {\bf{Explicit intents}} are used within the application for tasks such as switching between activities. They specify which component should be called. Kotilin: `intent = Intent(this, FooActivity::class.java) startActivity(intent);` {\emph{Implicit intents}} only specify the action to be performed, and are sent to the Android system which chooses which component should be used. Kotilin: `intent = \seqsplit{Intent(Intent.ACTION\_VIEW}, Uri.parse(URLStr)); startActivity(intent);`\{\{nl\}\} Activity needs {\bf{Intent Filter}} to receive implicit intents. `\textless{}intent-filter\textgreater{} \textless{}action android:name = "hkucs.myintentfilter" /\textgreater{} \textless{}category android:name = \seqsplit{"android.intent.category.DEFAULT"} /\textgreater{} \textless{}/intent-filter\textgreater{}` {\bf{Passing extra data}}: Sender: `myIntent.putExtra("ID", 6963)` Recpient: `val bundle: Bundle? = intent.extras\{\{nl\}\}bundle?.let \{bundle.apply \{ val inputString: String? = getString("ID") // id = 6963\}\}`% Row Count 20 (+ 20) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Fragment}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Must implement: {\bf{onCreate()}} - called when creating the fragment, should initialize essential components you want to retain when the fragment is paused or stopped, then resumed. {\bf{onCreateView}} - called when the fragment draws its user interface for the first time. Optional: {\bf{onPause()}} - called when the user is leaving the fragment. \newline % Row Count 7 (+ 7) {\bf{Kotilin implementation}} \newline % Row Count 8 (+ 1) `val manager: FragmentManager = supportFragmentManager\{\{nl\}\}val ft: FragmentTransaction = manager.beginTransaction()\{\{nl\}\}if (fragment != null) ft.replace(\textless{}ID of region in main layout\textgreater{}, \textless{}class name of fragment\textgreater{}(), \textless{}number tag to represent fragment\textgreater{}); \seqsplit{ft.commitAllowingStateLoss();`}% Row Count 14 (+ 6) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Service}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{StartService()}}: runs indefinitely even if caller app dies. Simple, single task. No return result. Cannot be called back or modified after it is sent out. \newline % Row Count 4 (+ 4) {\bf{BindService()}}: Can be bound to multiple components. Terminates if all callers die. Can be modified after being sent out. \newline % Row Count 7 (+ 3) A service can be both started and bound simulatenously. \newline % Row Count 9 (+ 2) {\bf{Activating service}}: `val intent = Intent(this, \seqsplit{HelloService::class.java);} startService(Intent);` \newline % Row Count 12 (+ 3) {\bf{Return value of onStartCommand()}}: \newline % Row Count 13 (+ 1) START\_NOT\_STICKY: Do not recreate after kill. Caller can restart unfinished jobs \newline % Row Count 15 (+ 2) START\_STICKY: Recreate, but do not redeliver last intent. Continuous work but stateless, e.g. media players. \newline % Row Count 18 (+ 3) \seqsplit{START\_REDELIVER\_INTENT:} Recreate, and redeliver last intent. Actively performing a job, e.g. file download% Row Count 21 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Storage}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{SharedPreferences}}: Private primitive data in key-value pairs (persistent storage) \newline % Row Count 2 (+ 2) {\bf{Bundles}}: Private primitive data in key-value pairs (temp storage for activity-fragment transfer) \newline % Row Count 5 (+ 3) {\bf{Internal storage}}: Private data on device memory \newline % Row Count 7 (+ 2) {\bf{External storage}}: Public data on internal or shared external storage, e.g., SD card \newline % Row Count 9 (+ 2) {\bf{SQLite database}}: Structured data (table) in a private database% Row Count 11 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}