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
TextView, EditText… inherit from which class?
View, which inherits from Object
Linear Layout, RelativeLayout… inherit from which class?
ViewGroup Class
Can a View, contain a ViewGroup?
No, an ViewGroup is a special type of View
You can draw to canvas, and to…?
A view
You should draw to a view when?
Your graphics don’t need to change dynamically
You should draw to a canvas when?
Your app needs to re-draw itself, such as in a game
What is lean back mode used for. how to bring back the nav bar?
when users wont be interacting with the screen, such as when watching a movie. Navbar is brought back with a tap
what is the immersive mode used for? how to bring back the system bars?
When users will be heavily interacting with the screen, bring back system bars by swiping in from edge
What is immersive sticky mode for?
intended for games that require a lot of swiping. navbar appears transparent if swiping in from edge, but will disapear if the screen is tapped, or after a few seconds
How would you keep track of multiple touches on the screen at once
By usiung a forloop that goes through the switch case, covering Event.down event.move and event.up
for every “pointer” on screnn
When implimenting accelorometer, which methods do you need to register/initialize/unregister the listener
onCreate, onPause and onResume
to listen for gestures, you will need to initialize what class>
The GestureDector class, then use gestureDetector.onTouchEvent(MotionEvent object) under onTouchEvent Overriden method
by using GestureDetector,onGestureListener, you have to then override all the gesture types, what should you do if you only want to override one type of gesture?`
by Extending GestureDetector.SimpleOnGestureListener, then using that class gestureDector = new GestureDetector(context, new MySimpleGestureListener()) where MySimpleGestureListener() is the class you just created which extends SimpleOnGestureListener.
what is an apk?
apk is the file format used by android for distribution