图片看不明白就看代码吧!有注释:
注册有两种方法:
第一种:手动注册,在类中重写onResume和onPause方法
第二种:在AndroidManifest.xml中注册添加
这里第一种和第二种方法都用了的。
activity_main.xml中代码(定义一个文本框和一个按钮):
<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:id="@+id/LinearLayout1"
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”
tools:context="