Mostly Android Flashcards
What are some of the things stored in the android manifest?
- Declares Package name
- Activities
- app name
- launcher icon
- permissions for the app
WHere are these defined: UI and Functionality
XML and Java Code (Activities)
Where in java code do you inflate the XML layout
In the onCreate method
With activity lifecycles, what are the four states?
Active, Visible, Hidden and Destroyed
in the activity stack, what’s the order? (Visible, Destroyed, Active and Hidden)
From top to bottom: Active-Visible-Hidden-Destroyed
When is the R class generated
When the application is compiled
What does the R class contain?
Contains access for all the resources in the res directory.
R.drawable.icon what is the datatype of this command?
A static Integer
How would you access Views? ie TextViews in XML
(TextView) findByView(R.id.textviewidname)
Can you find viewGroups the same way you find Views in java?
Yes, Viewgroups are just special types of View
how would you set up a button event listener with this code:
Button b =
(Button)findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() { public void onClick(View v){ // do something } });
How would you define onclick method in XML then access it from java
android:onClick=”onClick”
then java:
public void onclickSubmit(View v) { // some code }
How would you launch another activity from any given activity
With intents
launching an activity requires an explicit or implicit intent?
Explicit
When passing through data to a new intent, which method would you use?
intent.putExtra(“key”, value)
when recieving an intent from another activity, which method do you use, and what variable would you pass it?
intent.getStringExtra(“variable_name”);
What is an Implicit Intent? and an example
An implicit intent declares a general action to perform, which allows another app to handle the action. example: if you wanted to share text or images through social media, you would use an implicit intent to notify other apps that you have content to share
Implicit intents contain which information
Action - to perform
Data - URI or MIME type
Category - which type of component that can handle the intent
Extras - any extra info
What are the two types of context? Why would you use one over the other?
application context and activity context. Only use application context if it needs to live beyond your activity
what ways can you get access to context
this, getApplicationContext() (in an activity)
Explain the usefulness of the singleton pattern
if exactly one object is needed, as the singleton pattern restricts instantiation of a class to one instance
Features of a singleton class
Private static Singleton;
Private constructor;
public static method that returns instance of itself
Simple explaination of a Adapter pattern
Allows incompatible classes to work together by converting the interface of one class to match the other.
How do Array Adapters work with List Views and a string array?
ArrayAdapters create a view for each array item, by calling toString() on each time and placing the result in a textView