Android之记账本

这个ColaBox记事本是我从网上下载下来的拿来学习一下的(APK下载点这里。)

从登记收入与开支的页面跳转到账单页面运用了SQL数据库的录入,整体表的结构为:

db.execSQL("CREATE TABLE bills ("
                    + "_id INTEGER primary key autoincrement,"//ID
                    +" acctitemid integer,"//账目类型   
                    + "fee integer,"//费用
                    + "userid integer,"//使用者
                    + "sdate TEXT,"//日期
                    + "stime TEXT,"//时间
                    + "desc TEXT"    //  备注          
                    + ");");
Android中的PID:顾名思义,它指的是Process的id。每个进程都有一个独立的id,可以通过pid来区分不同的进程。
在网上把进程PID常用的API搜了一下记录于此:
android.os.Process.myPid( )
得到当前进程的pid
android.os.Process.killProcess ( int pid )
杀死相应进程号的进程
List<ActivityManager.RunningProcessInfo> getRunningAppProcesses( )
获取当前正在运行的进程
android.app.ActivityManager.RunningAppProcessInfo.pid
相应的RunningAppProcessInfo的pid
List<ActivityManager.RunningServiceInfo> getRunningServices ( int maxNum )
得到当前正在运行的ServiceInfo
android.app.ActivityManager.RunningServiceInfo.pid
相应的RunningServiceInfo的pid
而UID是应用在在Android中数据共享中,不同的应用有不同的UID,在Android中要实现UID共享数据只需在程序a,b中的menifest配置即可:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.perseus.a"
      android:versionCode="1"
      android:versionName="1.0"
          android:sharedUserId="com.share"
>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.perseus.b"
      android:versionCode="1"
      android:versionName="1.0"
          android:sharedUserId="com.share"
>
   db.execSQL("CREATE TABLE acctitem ("
                    + "_ID INTEGER PRIMARY KEY,"//ID
                    + "PID integer,"//PID
                    + "NAME TEXT"  // 姓名         
                    + ");");
账目表:
 db.execSQL("insert into acctitem values (1,null,'收入')");
          db.execSQL("insert into acctitem values (2,1,'工资')");
          db.execSQL("insert into acctitem values (9998,1,'其他')");
          db.execSQL("insert into acctitem values (0,null,'支出')");
          db.execSQL("insert into acctitem values (3,0,'生活用品')");
          db.execSQL("insert into acctitem values (4,0,'水电煤气费')");
          db.execSQL("insert into acctitem values (5,0,'汽油费')");
          db.execSQL("insert into acctitem values (9999,0,'其他')");
主类ColaBox:package com.cola.ui; 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.ImageView;
import android.widget.TextView;
 
public class ColaBox extends Activity {
  //定义线程
    private Handler mHandler = new Handler();
    ImageView imageview;
    TextView textview;
    int alpha = 255;
    int b = 0;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imageview = (ImageView) this.findViewById(R.id.ImageView01);
        textview = (TextView) this.findViewById(R.id.TextView01);
 
        Log.v("ColaBox", "ColaBox start ...");
        imageview.setAlpha(alpha);
       //线程
        new Thread(new Runnable() {
            public void run() {
                initApp();
                 
                while (b < 2) {
                    try {
                        if (b == 0) {
                            Thread.sleep(1000);
                            b = 1;
                        } else {
                            Thread.sleep(50);
                        }
 
                        updateApp();
 
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
 
            }
        }).start();
        //通过Handler运行线程所传递的信息
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                imageview.setAlpha(alpha);
                imageview.invalidate();
 
 
            }
        };
 
    }//更新
    public void updateApp() {
        alpha -= 5;
 
        if (alpha <= 0) {
            b = 2;
            Intent in = new Intent(this, com.cola.ui.Frm_Addbills.class);
            startActivity(in);
            this.finish();
        }
 
        mHandler.sendMessage(mHandler.obtainMessage());
 
    }
     //初始化
    public void initApp(){
         BilldbHelper billdb=new BilldbHelper(this);
           billdb.FirstStart();          
           billdb.close();
            
            
    }
 
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.v("cola", "keycode=" + keyCode);
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            Log.v("ColaBox", "ColaBox end ...");
            return true;
             
        }
        return false;
    }
}

运行效果:

不努力,还要青春干什么?
原文地址:https://www.cnblogs.com/caidupingblogs/p/5538965.html