●·● 目录:

package: others

G1 ………… Activity 类
G2 ………… ListActivity 类
G3 ………… Intent 类
G4 ………… Menu 类
G5 ………… MenuItem 类
       SubMenu 类
       ContextMenu 类
G6 ………… AndroidManifest.xml
G7 ………… Handler 类
G8 ………… Message 类
G9 ………… Bundle 类
Ga ………… Runnable 接口
Gb ………… Looper 类
Gc ………… HandlerThread 类
Gd ………… SQLiteDatabase 类
Ge ………… SQLiteOpenHelper 类



---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第G1个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● Activity 类

来源:android.app.Activity

1.An activity is a single, focused thing that the user can do.

2. Activity Method:

  • findViewById(int id):返回值: View. 通过 id 来找对应的控件.
  • requestWindowFeature(Window.FEATURE_NO_TITLE):activity 中不显示标题.
      注意此方法要写在 setContentView() 方法上面, 否则会报错.
  • setRequestedOrientation(int):设置默认的屏幕显示方向.
      ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:水平显示.
      ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:垂直显示.
  • setContentView(int layoutResID):设置当前 activity 的布局文件.
    setContentView(View view):

  • startActivity(Intent intent):加载一个新的 activity.
  • startActivityForResult(Intent intent, int requestCode):加载一个新的 activity, 同时可以接收此 activity 传过来的值.
  • onActivityResult(int requestCode, int resultCode, Intent data):得到返回的值.
         举个相关的例子
  • getBaseContext():返回值:Context.
  • getApplicationContext():返回值:Context. Return the context of the single, global Application object of the current process.
  • getIntent():返回值:Intent. 返回开始次 activity 的 intent.
  • getSharedPreferences(String name, int mode):返回值:SharedPreferences. 数据存储.
  • getApplication():返回值:Application. 返回拥有次 activity 的application.
  • getTaskId():返回值:int.
  • getPackageName():返回工程的包名称.
  • getLayoutInflater():返回值:LayoutInflater.
  • getResources():返回值:Resources.
      Resources 类:Class for accessing an application's resources.
        getString(int id):获取指定 id 的字符串.
        getStringArray(int id):获取指定 id 的字符串数组.
    String[] presidents;presidents = getResources().getStringArray(R.array.presidents_array);
  • getAssets():返回值:AssetManager.
      AssetManager 类:为程序提供一个进入 asset 文件夹的途径.  
        open(String fileName):返回值:final InputStream. 返回指定文件的读取流.
        open(String fileName, int accessMode):返回值:final InputStream.
    CopyDB(getBaseContext().getAssets().open("mydb"),    //文件的读取流.                    new FileOutputStream(destPath + "/MyDB"));  //文件的写入流.

  • finish():关掉 activity 时触发.
  • finishActivity(int requestCode):强制结束另外一个 activity

  • onCreate(Bundle savedInstanceState):当 activity 运行时触发.
  • onStart():当 activity 对于用户可见的时候触发.
  • onResume():当 activity 开始与用户交互的时候触发.
  • onPause():当当前的 activity 暂停.
      

  • onStop():当 activity 对于用户不可见的时候触发, 例如进入下一个 activity, 就是此 activity 在后台运行.
  • onRestart():当 activity 执行 onStop() 之后又重新开启的.
  • onDestroy():当 activity 结束的时候.
      当屏幕旋转的时候, activity 将依次执行下面方法:onPause(), onStop(), onDestroy() -- onCreate(), onStart(), onResume().
      若是想让反转前后 EditView 中的内容可以保留的话, 就一定要给 EditView 指定一个 id.


  • onCreateOptionsMenu(Menu menu):为 activity 创建菜单.
  • onCreateOptionsItemSelected(MenuItem item):选中菜单项的触发事件可以在此处写入.
  • onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo):为 activity 中的指定控件写入 context menu.
  • onSaveInstanceState(Bundle outState):
      ※ 参考:关于Activity的onSaveInstanceState调用时机的说明
      
      
      
  • onKeyDown(int keyCode, KeyEvent event):返回值:boolean. 当控件不触发此按键的时候, 才触发.
      keyCode 值可以通过 KeyEvent 中获取, 包括一些常量. 包括:KEYCODE_BACK
     
     ※ 参考:Android系统onKeyDown监控/拦截/监听/屏蔽返回键、菜单键和Home键
      ※ 参考:点击两次back退出程序
       Return true to prevent this event from being propagated further, or false to indicate that you have not handled this event and it should continue to be propagated.
      当返回值为 true 的时候, 只是执行事件内部的内容, 例如按 ↓ 就不会移动到下一个控件, 阻止进一步执行. 当返回值为 false 的时候, 不仅执行事件内部的内容, 同时还会执行按键本来具有的功能!
      
      
  • onTouchEvent(MotionEvent event):屏幕点击触发事件.
      ※ 参考:按键事件,KeyEvent
         点击屏幕, 显示坐标
  • onCreateDialog(int id):重写创建对话框. (不推荐)
  • showDialog(int id):显示对应上面创建的对话框. id 为唯一标识符.

通过在 Manifest.xml 中修改 android:theme 可以修改 Activity 的主题样式.
可以写在 <application> 标签中, 也可以写在 <activity> 标签中.
※ 参考:android UI进阶之style和theme的使用
※ 参考:Android风格与主题(style and theme)

android:theme="@android:style/Theme.Black"      //黑色背景android:theme="@android:style/Theme.Wallpaper"    //以桌面背景为背景android:theme="@android:style/Theme.Translucent"    //透明背景android:theme="@android:style/Theme.InputMethod"    //透明, 输入的形式展现android:theme="@android:style/Theme.Dialog"      //对话框形式显示

※ 参考:Activity生命周期详解
※ 参考:Android activity的生命周期

☀☀☀<< 举例 >>☀☀☀

接收后面 Activity 中的内容:

     MainActivity.java      second.java

效果:MainActivity 中点击 Button11 → second 中点击 Button21 ---------- Button11(Go) -- Button21(Back) 其他类似!!!!

参考:《Android开发从零开始》——7.Intent初级学习 (内容在视频中)

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第G2个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● ListActivity 类

来源:android.app.ListActivity

1. An activity that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item.

2. ListActivity Method:

  • getListAdapter():返回值: ListAdapter. Get the ListAdapter associated with this activity's ListView.
  • setListAdapter(ListAdapter adapter):Provide the cursor for the list view.
  • getListView():返回值:ListView. Get the activity's list view widget.
  • getSelectedItemId():返回值:long. Get the cursor row ID of the currently selected list item.
  • getSelectedItemPosition():返回值:int. Get the position of the currently selected list item.
  • setSelection(int position):Set the currently selected list item to the specified position with the adapter's data

  • onDestroy():Perform any final cleanup before an activity is destroyed.
  • onListItemClick(ListView l, View v, int position, long id):This method will be called when an item in the list is selected.
  • onRestoreInstanceState(Bundle state):Ensures the list view has been created before Activity restores all of the view states.

●·●ExpandableListActivity 类

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第G3个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● Intent 类

来源:android.content.Intent

1.An intent is an abstract description of an operation to be performed.

  ※ 参考:整理下 Intent 中文API (包括 Intent 中的常量)

2. Intent Constructors:

  • Intent():创建一个空的 intent.
  • Intent(Intent o):复制构造函数.
  • Intent(String action):通过给定的 action-name 建立 intent, 可以调用外部程序.
      例如:可以调用发短信, 打电话之类的. Intent.ACTION_DIAL 也可以调用其他程序的 activity.
      对于自己写的 activity, 可以在 Manifest.xml 中的 <intent-filter> 中加入 <action>
      若两个不同的 activity 有相同的 <action> 那么调用的时候就会出现一个选择对话框, 选择想要跳转的 activity, 另外也可以勾选下面的复选框, 作为默认跳转, 想要删除, 到应用程序中点击 "清除默认值".
    <activity    <intent-filter >        <action android:name="net.learn2develop.SecondActivity" />   ...
  • Intent(String action, Uri uri):Create an intent with a given action and for a given data url.
      第一个参数:传入的 action,可以是自己写的,也可以系统自带的,打电话、发短信什么的。
      第二个参数:类似 setData() 达到的效果,就是传进去一个数据,可能是电话号码,网址,经纬度坐标等等。  
  • Intent(Context packageContext, Class<?> cls):创建一个包括 setClass 方法的 intent.
      activity 都在一个程序内部的时候, 用此构造函数.
  • Intent(String action, Uri uri, Context packageContext, Class<?> cls):Create an intent for a specific component with a specified action and data.

3. Intent Method:

  • setClass(Context packageContext, Class<?> cls):返回值:Intent.
      第一个参数:此 activity.
      第二个参数:要转向的 activity.
  • setFlags(int flags):Set special flags controlling how this intent is handled.
      FLAG_ACTIVITY_CLEAR_TOP:例如:A,B,C,D,从D切换到B,则会结束掉B之间的C和D.
    ※ 参考:打开多个Activity,返回到第一个Activity的问题


  • putExtra(String name, String value):返回值:Intent. Add extended data to the intent. (有N多重写的方法)
      在前面的 Activity 中传递数据.
  • getStringExtra(String name):返回值:String. Retrieve extended data from the intent. (获取上面赋予的值)
      在后面的 Activity 中得到数据.

  • putExtra(String name, int value):返回值:Intent. 增加整型数据.
  • getIntExtra(String name):返回值:int. 取回整形数据.
  • putExtra(String name, char value):返回值:Intent. 增加字符.
  • getCharExtra(String name):返回值:char. 取回字符.
  • putExtra(String name, String[] value):返回值:Intent. 增加字符串数组.
  • getStringArrayExtra(String name):返回值:String[]. 取回字符串数组.
  • putExtra(String name, int[] value):返回值:Intent. 增加整型数组.
  • getIntArrayExtra(String name):返回值:int[]. 取回整型数组.

  • setData(Uri data):给正在操作的 intent 赋值.
  • getData():返回值:Uri. 从正在操作的 intent 中取值. 读取上面赋的值.

  • createChooser(Intent target, CharSequence title):返回值:static Intent. 直接用在 startActivity() 方法中.
      第一个参数:intent.
      第二个参数:选择目标的时候显示的标题内容.
      

☀☀☀<< 举例 >>☀☀☀

     举个例子

※ 注意:在加入新的 activity 后, 要在 AndroidManifest.xml 中给 activity 注册.

        <activity             android:name=".lv"    //点后面为 *.java 的名称.            android:label="lvlvlvlv">  //显示的名称.        </activity>

android:name 表示的是 activity 的名称, 唯一标识的.
android:label 表示的是 activity 的显示标题.

☀☀☀<< 举例 >>☀☀☀

按钮发短信:

     View Code

在 Manifest.xml 中添加许可.

    <uses-permission android:name="android.permission.SEND_SMS"/>

  

  


  

  


由上可见,其实 Action 是传递的动作,也就是想要干什么,Uri 则就是一个携带的数据,从一侧传入,从另一侧取出使用,如上面的 setData() 方法。



会出现选择框,上面是Browser(默认的),下面是 Intents(自己写的 WebVie)。

※ 参考:《Android开发从零开始》——7.Intent初级学习

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第G4个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● Menu 类

来源:android.view.Menu

1.Interface for managing the items in a menu.

2. Menu Method:

  • add(int groupId, int itemId, int order, int titleRes):返回值:MenuItem. 为菜单增加一个菜单项.
  • add(int groupId, int itemId, int order, charSequence title):
  • addSubMenu(int groupId, int itemId, int order, CharSequence title):返回值:SubMenu. 为菜单增加一个菜单项, 点击此菜单项可以进入二级菜单项.
  • addSubMenu(int groupId, int itemId, int order, int titleRes):
  • clear():清除所有菜单项.
  • getItem(int index):获取指定索引的菜单项.

※ 参考:Android学习——编写菜单

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第G5个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● MenuItem 类

来源:android.view.MenuItem

1.Interface for direct access to a previously created menu item.

2. MenuItem Method:

  • getItemId():返回值:int. 获取该菜单项的 id.
  • getOrder():返回值:int. 获取该菜单的 order.
  • setAlphabeticShortcut(char alphaChar):改变字母快捷键与该菜单项关联.
  • setIcon(int iconRes):给菜单项设置图标.

●·● SubMenu 类

来源:android.view.SubMenu

1.Interface for direct access to a previously created menu item.

2. SubMenu Method:

  • add(int groupId, int itemId, int order, int titleRes):返回值:MenuItem. 为二级菜单增加一个菜单项.

●·● ContextMenu 类

来源:android.view.ContextMenu

1.Extension of Menu for context menus providing functionality to modify the header of the context menu.

2. ContextMenu Method:

  • setHeaderTitle(CharSequence title):为 context menu 设置指定的标题.
  • setHeaderTitle(int titleRes):
  • setHeaderIcon(int iconRes):为 context menu 设置指定的 Icon.
  • setHeaderView(View view):为 context menu 设定 view.

※ 参考:android的Menu使用

☀☀☀<< 举例 >>☀☀☀

效果:

1. 左边实现主菜单的显示, 同时点击 Option 会显示如右图所示的菜单.
2. 右边同时也是长按屏幕显示的 ContextMenu 菜单.

☀☀☀ 主菜单及二级菜单及点击菜单实现代码:

1> 定义菜单在 onCreateOptionMenu 方法中.
2> Menu 定义主菜单, MenuItem 定义普通的菜单项, SubMenu 定义二级菜单项.
  重写 onOptionsItemSelected(MenuItem item) 方法 或
  重写 onMenuItemSelected(int featureId, MenuItem item) 方法.

     View Code      View Code

ContextMenu 可以实现长按控件显示菜单, 首先在 onCreate 函数中将想要 Context Menu 的控件先注册, 然后在 onCreateContextMenu 方法中写入相应的菜单选项.

     View Code      View Code

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第G6个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● AndroidManifest.xml

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第G7个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● Handler 类

来源:android.os.Handler

1.A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue.

2. Handler Methods:

  • getMessageName(Message message): 返回值:String. Returns a string representing the name of the specified message.
  • handleMessage(Message msg):Subclasses must implement this to receive messages.
  • post(Runnable r):返回值:boolean. Causes the Runnable r to be added to the message queue.
  • postAtFrontOfQueue(Runnable r):返回值:boolean. Posts a message to an object that implements Runnable.
  • postAtTime(Runnable r, Object token, long uptimeMillis):返回值:boolean. Causes the Runnable r to be added to the message queue, to be run at a specific time given by uptimeMillis.
  • postAtTime(Runnable r, long uptimeMillis):返回值:boolean.
  • postDelayed(Runnable r, long delayMillis):返回值:boolean. Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.
  • removeCallbacks(Runnable r):Remove any pending posts of Runnable r that are in the message queue.
  • removeCallbacks(Runnable r, Object token):Remove any pending posts of Runnable r with Object token that are in the message queue.
  • removeCallbacksAndMessages(Object token):Remove any pending posts of callbacks and sent messages whose obj is token.
  • removeMessages(int what):Remove any pending posts of messages with code 'what' that are in the message queue.
  • sendEmptyMessage(int what):返回值:boolean. Sends a Message containing only the what value.
  • sendEmptyMessageAtTime(int what, long uptimeMillis):返回值:boolean. Sends a Message containing only the what value, to be delivered at a specific time.
  • sendEmptyMessageDelayed(int what, long delayMillis):返回值:boolean. Sends a Message containing only the what value, to be delivered after the specified amount of time elapses.
  • sendMessage(Message msg):返回值:boolean. Pushes a message onto the end of the message queue after all pending messages before the current time.
  • sendMessageAtFrontQueue(Message msg):返回值:boolean. Enqueue a message at the front of the message queue, to be processed on the next iteration of the message loop.
  • sendMessageAtTime(Message msg, long uptimeMillis):返回值:boolean. Enqueue a message into the message queue after all pending messages before the absolute time (in milliseconds) uptimeMillis.
  • sendMessageDelayed(Message msg, long delayMillis):返回值:boolean.Enqueue a message into the message queue after all pending messages before (current time + delayMillis).

※ 参考:[转]Android的Handler总结

※ 参考:Handler初探

☀☀☀<< 举例 >>☀☀☀

     举个例子

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第G8个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● Message 类

来源:android.os.Message

1.Defines a message containing a description and arbitrary data object that can be sent to a Handler.

2. Message Methods:

  • copyFrom(Message o):Make this message like o.
  • describeContents():返回值:int. Describe the kinds of special objects contained in this Parcelable's marshalled representation.
  • getCallback():返回值:Runnable. Retrieve callback object that will execute when this message is handled.
  • getData():返回值:Bundle. Obtains a Bundle of arbitrary data associated with this event, lazily creating it if necessary.
  • getTarget():返回值:Handler. Retrieve the a Handler implementation that will receive this message.
  • getWhen():返回值:long. Return the targeted delivery time of this message, in milliseconds.
  • obtain():返回值:Message. Return a new Message instance from the global pool.
  • peekData():返回值:Bundle. Like getData(), but does not lazily create the Bundle.
  • recycle():Return a Message instance to the global pool.
  • sendToTarget():Sends this Message to the Handler specified by getTarget().
  • setData(Bundle data):Sets a Bundle of arbitrary data values.
  • setTarget(Handler target):
  • writeToParcel(Parcel dest, int flags):Flatten this object in to a Parcel.

3. Message Fields:

  • arg1:返回值:int.
  • arg2:返回值:int.
  • obj:返回值:Object.

☀☀☀<< 举例 >>☀☀☀

     举个例子

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第G9个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● Bundle 类

来源:android.os.Bundle

1. 用于在 Activity 之间传递变量的值.

2. Bundle Methods:

  • clear():Removes all elements from the mapping of this Bundle.
  • clone():返回值:Object. Clones the current Bundle.
  • containKey(String key):返回值:boolean. Returns true if the given key is contained in the mapping of this Bundle.
  • describeContents():返回值:int.
  • get(String key):返回值:Object.
  • getBoolean(String key):返回值:boolean.
  • getBundle(String key):返回值:Bundle.

首先在前一个 Activity 中传入数据.

Intent intent = new Intent();intent.setClass(BmitestActivity.this, report.class);Bundle bundle = new Bundle();  //新建 bundlebundle.putString("key", "Hello");  //传入值intent.putExtras(bundle);  //将 bundle 加入到 intent 中

在后一个 Activity 中取出数据.

Intent intent = getIntent();Bundle bundle = intent.getExtras();  //获取 bundleToast.makeText(report.this, bundle.getString("key"), Toast.LENGTH_SHORT).show();  //取值

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第Ga个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● Runnable 接口

来源:java.lang.Runnable

1. Represents a command that can be executed. Often used to run code in a different Thread.

2. Bundle Methods:

  • run():Starts executing the active part of the class' code.

※ 参考:Android中Thread,hanlder(HanlderThread),Runnable之间的关系

※ 参考:Android 线程 thread 两种实现方法!

※ 参考:Java中继承thread类与实现Runnable接口的区别

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第Gb个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·● Looper 类

来源:android.os.Looper

1. Class used to run a message loop for a thread.

2. Looper Methods:

  • getMainLooper():返回值:static Looper. 返回程序的主 looper.
  • myLooper():返回值:static Looper. 返回与当前线程关联的 Looper 对象.
  • myQueue():返回值:static MessageQueue.返回与当前线程关联的 MessageQueue 对象.
  • prepare():初始化当前线程为一个 looper.
  • prepareMainLooper():初始化当前线程为主 looper.
  • getThread():返回值:Thread. 返回与此 Looper 相关联的进程.
  • quit():退出 looper.
  • notify():
  • notifyAll():
  • wait():
  • wait(long millis):

---------------------------------------------------------------------------------------------------------

╔════════╗
╠════╣ 第Gc个 ╠══════════════════════════════════════════════════╣
╚════════╝

●·●

更多相关文章

  1. android 串口jni 开发流程
  2. Android网络解析
  3. webkit中的javascript和android交互
  4. Android(安卓)使用volley过程中遇到的问题解决办法
  5. Android获取Java类名/文件名/方法名/行号
  6. Android获取联系人头像的方法
  7. android 异步加载图片缩略图
  8. Android(安卓)SQLiteDatabase中query、insert、update、delete方
  9. android关于手机和3.0版本以上平板去标题问题

随机推荐

  1. android子线程中刷新界面控件
  2. 从 android sqlite 中获取boolean值
  3. Android(安卓)WebView中的JavaScript调用
  4. Android(安卓)控件的显示和隐藏
  5. Android(安卓)轮询实现的三种方式
  6. 切换选项卡
  7. Android系统属性SystemProperties.set/ge
  8. 编译V8静态库 for Android
  9. android开源工程
  10. Android(安卓)Ble