This is an old revision of the document!
Android Developer Interview
Basic
Suppose you have a v-shape array, e.g [1, 12, 31, 44, 51, 54, 23, 22, 10]. How to find the maximum value in a v-shape array?
假如我们有一个v-shape数组,如[1, 12, 31, 44, 51, 54, 23, 22, 10]。怎样找出它的最大值?
Android
Question 1
- Describe three common use cases for using an Intent.
Question 2
- Under what condition could the code sample below crash your application? How would you modify the code to avoid this potential problem? Explain your answer.
Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage); sendIntent.setType(HTTP.PLAIN_TEXT_TYPE); // "text/plain" MIME type startActivity(sendIntent);
Question 3
- What is the relationship between the life cycle of an AsyncTask and an Activity? What problems can this result in? How can these problems be avoided?
Question 4
- What is difference between Serializable and Parcelable ? Which is best approach in Android ?
Question 5
public class MainActivity extends Activity implements OnClickListener {
final String TAG = "States";
Button btnActTwo;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnActTwo = (Button) findViewById(R.id.btnActTwo);
btnActTwo.setOnClickListener(this);
Log.d(TAG, "MainActivity: onCreate()");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "MainActivity: onRestart()");
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "MainActivity: onStart()");
}
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "MainActivity: onResume()");
}
@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "MainActivity: onPause()");
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "MainActivity: onStop()");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "MainActivity: onDestroy()");
}
@Override
public void onClick(View v) {
Intent intent = new Intent(this, ActivityTwo.class);
startActivity(intent);
}
}
public class ActivityTwo extends Activity {
final String TAG = "States";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.two);
Log.d(TAG, "ActivityTwo: onCreate()");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "ActivityTwo: onRestart()");
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "ActivityTwo: onStart()");
}
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "ActivityTwo: onResume()");
}
@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "ActivityTwo: onPause()");
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "ActivityTwo: onStop()");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "ActivityTwo: onDestroy()");
}
}
public class ActivityThree extends Activity {
final String TAG = "States";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.three);
Log.d(TAG, "ActivityThree: onCreate()");
this.finish();
}
@Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "ActivityThree: onRestart()");
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "ActivityThree: onStart()");
}
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "ActivityThree: onResume()");
}
@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "ActivityThree: onPause()");
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "ActivityThree: onStop()");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "ActivityThree: onDestroy()");
}
}
- Write down the log results at 4 different cases
- Start MainActivity
- Invoke onClick() at MainActivity
- User press back button from ActivityTwo
- Start ActivityThree