Part II - Fill in the blanks.
Click to jump to the first part
25. The four commonly used layouts in android are
Framlayout,Linearlayout,Relativelayout,Tablelayout。
26. The four major components of android
activity,service,broadcast,contentprovide。
27. The ObjectInputStream and ObjectOutputStream classes in the java.io package are mainly used for reading and writing objects.
28. The implementation methods of service in android are startservice and bindservice.
29. Activity generally overloads 7 methods to maintain its life cycle, in addition to onCreate, onStart, onDestory, and onRestart, onResume, Onpause, Onstop.
30.android data storage methods include SharedPrefrerence, file storage, SQLite, contentProvider and network.
31. When an Activity is started and the new Activity is executed, the callback function that needs to be returned to the Activity that started it to execute is StartActivityResult().
32. It involves the command line, so it will not be sorted out.
33. The result of the program running is: goodandgbc.
public class Example { String string = new String("good"); char[] chars = {'a', 'b', 'c'}; public static void main(String args[]) { Example example = new Example(); example.change(example.string, example.chars); System.out.print(example.string + "and"); System.out.print(example.chars); } public void change(String string, char chars[]) { string = "test OK"; chars[0] = 'g'; } }
34. In android, please briefly describe the calling process of jni.
Install and download Cygwin, download Android NDK
Involvement of JNI interfaces in NDK projects
Implement native methods using C/C++
JNI generates dynamic link library .so file
Copy the dynamic link library to the project and call it
35. Briefly describe the structure of Android applications?
Linux Kernel
Libraries (system runtime library or c/c++ core library)
Application Framework (development framework package)
Applications
36. Please inherit the implementation of SQLiteOpenHelper
1) Create a database of "diaryOpenHelper.db" with version 1
2) Create a "diary" table at the same time (contain a _id primary key and grow automatically, topic character type 100 length, content character type 1000 length
3) Drop the "diary" table when the database version changes, and recreate the "diary" table
public class DBHelper extends SQLiteOpenHelper { public final static String DBNAME = "diaryOpenHelper.db"; public final static Integer DBVERSION = 1; // Create database public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { super (context, name, factory, version); } // Create table structure file @Override public void onCreate(SQLiteDatabase db) { String sql = "CREATE TABLE `diary`(`_id` INTEGER PRIMARY KEY AUTOINCREMENT, `topic` VARCHAR(100), `content` VARCHAR(1000))"; db.execSQL(sql); } // If the database version is updated, call this method @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { String sql = "DROP TABLE IF EXISTS `diary`"; db.execSQL(sql); this.onCreate(db); } }
37. The existing ProgressBar control progressBar on the page, please use the writing thread to complete its progress display work in 10 seconds
public class ProgressBarStu extends AppCompatActivity { ProgressBar progressBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_progress_bar); progressBar = findViewById(R.id.progressBar); // Create a new thread Thread = new Thread( new Runnable() { @Override public void run() { // Get the total length of the progress bar int progressBarMax = progressBar .getMax(); // Get 1/ 10 int stepProgress = progressBarMax / 10 ; // if the progress bar is not finished while (progressBarMax != progressBar .getProgress()) { // get the length of the current progress bar int currentProgress = progressBar .getProgress(); // set the current progress bar The progress bar adds 1/10 to the length of the run progressBar.setProgress(currentProgress + stepProgress); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace (); } } } }); thread.start(); } }
38. Please describe the life cycle of Activity
There are three methods that must be called onCreate()——>onStart()——>onResume()
Not completed, will be added after verification.
39. If the background activity is recycled by the system for some reason, how to save the current state before being recycled by the system?
onSaveInstanceState()
When an ActivityA in your program is running and another new ActivityB is actively or passively running, ActivityA will execute onSaveInstatanceState() at this time. When ActivityB is finished, it comes back to find ActivityA. At this time, there are two situations:
1. ActivityA is recycled. At this time, ActivityA will call onCreate() again, but this onCreate() takes the parameter saveInstanceState.
2.ActivityA没被回收,直接调用onResume(),跳过了onCreate()。
40.如何将一个Activity设置为窗口的样式?
在AndroidManifest.xml中给Activity添加主题样式
android:theme="@style/Theme.AppCompat.Dialog"
41.如何退出Activity?如何安全退出已调用多个Activity的Application?
有tai待chang商le榷la
42.请介绍下Android中常用的五种布局。
FrameLayout 框架布局
LinearLayout 线性布局
AbsoluteLayout 绝对布局
RelativeLayout 相对布局
TableLayout 表格布局
43.请介绍Android的数据存储方式
SharedPreferences方式
文件存储方式
SQLite数据库方式
Content Provider方式
网络存储方式
44.