編輯:關於Android編程
package cn.testservice1;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;
/**
* Demo描述:
* 采用startService()方法啟動服務
* 在此只是簡單地模擬該過程
*/
public class MainActivity extends Activity {
private Button mStartButton;
private Button mStopButton;
private Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
intent=new Intent();
intent.setAction("cc.test.com");
//開啟服務
mStartButton=(Button) findViewById(R.id.startButton);
mStartButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
startService(intent);
}
});
//終止服務
mStopButton=(Button) findViewById(R.id.stopButton);
mStopButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
stopService(intent);
}
});
}
}
package cn.testservice1;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class ServiceSubclass extends Service {
@Override
public IBinder onBind(Intent arg0) {
return null;
}
public void onCreate() {
System.out.println("---> Service onCreate()");
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
System.out.println("---> Service onStart()");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
System.out.println("---> Service onStartCommand()");
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
System.out.println("---> Service onDestroy()");
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
>
<Button
android:id="@+id/startButton"
android:layout_width="200dip"
android:layout_height="150dip"
android:text="啟動Service"
/>
<Button
android:id="@+id/stopButton"
android:layout_width="200dip"
android:layout_height="150dip"
android:text="停止Service"
/>
</LinearLayout>
android webview與js交互(動態添加js)
1、本地html與本地html裡的js交互2、本地html與本地js交互3、網絡html與網絡js交互4、網絡html與本地js交互5、各個情況動態添加js以上5點都可以
Android應用中通過Layout_weight屬性用ListView實現表格
今天主要說的是對Layout_weight屬性的完全解析,以及利用Layout_weight這個屬性使用ListView來實現表格的效果,我們都知道Android裡面專門
安卓開發中內存問題分析(一)工具篇
內存洩漏和內存溢出是安卓開發中經常碰到的問題,如何能夠快速有效的發現並追蹤內存洩漏或者內存溢出的源頭,是每個開發者都需要掌握的技巧,今天我給大家帶來常見的內存分析工具使用
國行華為手表多少錢 華為watch國行各版本售價對比
一直以來花粉都很期待華為智能手表國行版的發布,今天下午隨著華為發布會華為watch一同發布,發布的手機新品是華為Mate8。很想知道國行華為手表多少錢?有幾