Last active
August 29, 2015 14:04
-
-
Save EbenezerGH/60b3a67b0cca02300bae to your computer and use it in GitHub Desktop.
Filling in the gaps of my Android knowledge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-Favor Anonymous Inner Classes for Listeners(http://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html#declaring-anonymous-classes) | |
-Use Fragments for ALL Interfaces after introduced in Chap. 7 | |
-Applications written are compatible with Gingerbread and Froyo Devices (I won't worry about this) | |
Chapter 1 | |
Your First Android Application | |
------------------------------ | |
-No Notes | |
Chapter 2 | |
Android and Model-View-Controller | |
--------------------------------- | |
-Objects are seperated into 3 sections(Fig 2.4 pg 35) | |
-model: Holds, manages data | |
-controller: Logic that ties model & View together | |
-view(layout,xml, anything seeable): Responds to user input | |
-Android states that any object created must be a model, controller, or a view | |
-Furthermore this will help form an organized architecture for any application you create | |
no matter how compicated | |
-It makes classes easier to reuse | |
Chapter 3 | |
The Activity Lifecycle | |
---------------------- | |
Activities have 3 possible states(Fig.3.1 pg 53) | |
-Running: Visibile in forground | |
-Paused: visible | |
-Stopped: not visible | |
-Subclasses onCreate(), OnStart(), OnResume(), onPause(), OnStop(), and OnDestroy() transition through the activity states | |
-When Logging TAG constants are a common practice and allows the programmer to easily find TAGs | |
-Resource file res/layout-land is used to create a seperate layout in the landscape orientation | |
--Framelayouts are easiest to use bcause they do not rearrange children | |
Saving Data Across Rotation using Bundle(Listing 3.5 pg 66) | |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | |
Override onSaveInstanceState | |
private static final String TAG = "QuizActivity" | |
private static final String KEY_INDEX = "index" | |
@Override | |
public void onSaveInstanceState(Bundle savedInstanceState) | |
{ | |
super.onSaveInstanceState(savedInstanceState); | |
Log.i(TAG, "onSaveInstanceState") | |
savedInstanceState.putInt(KEY_INDEX, mCurrentIndex); | |
} | |
In onCreate.. | |
if(savedInstanceState != null) | |
{ | |
mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0) | |
} | |
Chapter 4 | |
Debugging Android Apps | |
----------------------- | |
https://developer.android.com/sdk/installing/studio-debug.html | |
DDMS: Dalvik Debug Monitor Service | |
Debugger | |
green circle: public variable | |
blue triangle: defualt variable | |
yellow diamond: protected variable | |
red square: private variable | |
-Exception Breakpoints can be used stop when caught/uncaught exceptions are thrown | |
-Android Lint is a static analyzer | |
--Static Analyzers find defects in code without running it | |
-How to fix issues with the R class(pg 87) | |
--Run Android Lint | |
--Clean Your Project | |
--Recheck the validity of the XML in your resource files | |
--Delete your gen directory | |
Chapter 5 | |
Your Second Activity | |
-------------------- | |
Start Activity | |
Intent i; | |
i = new Intent(FirstActivity.this, SecondActivity.class); | |
startActivity(i); | |
Explicit Intent: used to start Activities within your appli ation and use a Context | |
Implicit Intent: used when you want to start an activity in another application(Read More Chap.21) | |
Extras: Arbitrary data that the calling activity can include with an intent. | |
Intent.putExtra(...) | |
Method being called: | |
public Intent putExtra(String name, boolean value) | |
-Using package name prevents name collisions when deifining extra. | |
public static final String EXTRA_ANSWER_IS_TRUE = "package.blahblah" | |
Sending Values | |
-=-=-=-=-=-=-= | |
@Override | |
public void onClick(View v) | |
{ | |
Intent i = new Intent(FirstActivity.this, SecondActivity.class); | |
boolean answerIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion(); | |
i.putExtra(SecondActivity.EXTRA_ANSWER_IS_TRUE, answerIsTrue); | |
startActivity(i); | |
} | |
}); | |
} | |
Retrieving Values | |
-=-=-=-=-=-=-=-=- | |
public boolean getBooleanExtra(String name, boolean defaultValue) | |
In 2nd Activity: | |
private boolean mAnswerIsTrue; | |
mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE, false); | |
Retrieving Values back from child Activity | |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | |
requestCode: user-defined integer that is sent to the child activity and then received back by the parent | |
public void startActivityForResult(Intent intent, int requestCode) | |
In Child call | |
public final void setResult(int resultCode) or | |
public final void setResult(int resultCode, Intent data) | |
resultCode is usually Activity.RESULT_OK or Activity.RESULT_CANCELED | |
Using onActivityResult(int requestCode, int resultCode, Intent data) | |
to retrieve results works as well, but you would have to create your own conditional statements | |
Chapter 6 | |
Android SDK Versions and Compatibility | |
-------------------------------------- | |
http://developer.android.com/about/dashboards/index.html | |
-Old Book so will only be writing down Relevent material | |
-A common practice when dealing with compatibility of differnt SDK versions is to use conditional statements | |
to load different features based on the SDK version | |
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) | |
{ | |
ActionBar actionBar = getActionBar(); | |
actionBar.setSubtitle("Bodies of Water"); | |
} | |
Build.VERSION.SDK_INT is a constant that holds the device's version of Android | |
@TargetApi(#) | |
This is a surpressor warning. With this the lint filter will ignore the following code and prevent lint errors from | |
showing up when referring to a specific build version | |
Android Developer Documentation is available without connecting to the internet, they're available in filesystem | |
Continue.. | |
Chapter 7 | |
UI Fragments and the Fragment Manager | |
------------------------------------- | |
Accidently deleted everything... Just go to page 125. Dammit.. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment