phonetest

来源:互联网 发布:淘宝最常见韩国模特 编辑:程序博客网 时间:2024/05/20 05:53

package com.hyf.service;

 

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

 

 

public class RecordisBootReciever extends BroadcastReceiver {

    public static int shutdowntimes;

    public static int startuptimes;

private static final String TAG="RecordShutdownTimes";

@Override

public void onReceive(Context context, Intent intent) {

// TODO Auto-generated method stub

if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())){

startuptimes++;

}

shutdowntimes=(shutdowntimes==0)?0:startuptimes-1;

}

 

}

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

 

package com.hyf.test;

 

import com.hyf.service.RecordisBootReciever;

 

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.TextView;

 

public class ShutDownTimesActivity extends Activity {

private TextView startuptimes;

private TextView shutdowntimes;

Button startuptimesButton;

Button shutdowntimesButton;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        startuptimesButton=(Button)findViewById(R.id.startuptimesButton);

        shutdowntimesButton =(Button)findViewById(R.id.shutdowntimesButton);

        startuptimes= (TextView)findViewById(R.id.startuptimes);

        shutdowntimes=(TextView)findViewById(R.id.shutdowntimes);

        startuptimesButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

// TODO Auto-generated method stub

startuptimes.setText(RecordisBootReciever.startuptimes);

setContentView(R.layout.main);

}

});

        shutdowntimesButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

// TODO Auto-generated method stub

shutdowntimes.setText(RecordisBootReciever.shutdowntimes);

setContentView(R.layout.main);

}

});

    }

}

 

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

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<LinearLayout

   android:orientation="horizontal"

   android:layout_width="fill_parent"

   android:layout_height="fill_parent"

   android:layout_weight="1"

   >

    <Button

       android:id="@+id/startuptimesButton"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:text="@string/startuptimesButton"

       />

   <TextView

       android:id="@+id/startuptimes"

       android:layout_width="150dip"

       android:layout_height="wrap_content"

       android:background="#aaaa00"

  />

</LinearLayout>      

<LinearLayout

   android:orientation="horizontal"

   android:layout_width="fill_parent"

   android:layout_height="fill_parent"

   android:layout_weight="1"

   >

    <Button

       android:id="@+id/shutdowntimesButton"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:text="@string/shutdowntimesButton"

       />

   <TextView

       android:id="@+id/shutdowntimes"

       android:layout_width="150dip"

       android:layout_height="wrap_content"

       android:background="#aaaa00"

       />

</LinearLayout>        

</LinearLayout>

----------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.huawei.test"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".ShutDownTimesActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".RecordisBootReciever">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>
    <uses-sdk android:minSdkVersion="8" />
</manifest> 

原创粉丝点击