안드로이드 개발 정보
(글 수 1,067)
개발강좌에 글을 올리지만 추후 제가 사용하기 위해서 test app 를 올립니다. ㅎ
Test Activity
참고
프로페셔널 안드로이드 애플리케이션 개발 (343p~354p)
android Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lowmans.MyServiceTest"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MyServiceTest"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="MyService">
<intent-filter>
<action android:name="lowmans.MyServiceTest.MyService" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
</application>
</manifest>
main.xml
<?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"
>
<Button
android:text="ServiceStart"
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:text="ServiceStop"
android:id="@+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Test Activity
package lowmans.MyServiceTest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MyServiceTest extends Activity implements OnClickListener{
final String tag = "MyServiceTest";
private Button mStart;
private Button mStop;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mStart = (Button)findViewById(R.id.Button01);
mStop = (Button)findViewById(R.id.Button02);
mStart.setOnClickListener(this);
mStop.setOnClickListener(this);
}
public void onClick(View v){
switch(v.getId()){
case R.id.Button01:
Log.i(tag , "Start Button OnClick");
Intent serviceStart = new Intent("lowmans.MyServiceTest.MyService");
startService(serviceStart);
break;
case R.id.Button02:
Log.i(tag , "Stop Button OnClick");
Intent serviceStop = new Intent("lowmans.MyServiceTest.MyService");
stopService(serviceStop);
break;
}
}
}
Test Service
package lowmans.MyServiceTest;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class MyService extends Service {
final String tag = "MyService";
public void onCreate(){
Log.i(tag , "onCreate");
}
public void onStart(Intent intent , int startId){
Log.i(tag , "onStart");
}
public void onDestroy(){
Log.i(tag , "onDestroy");
}
public IBinder onBind(Intent intent){
return null;
}
}
아 서비스쪽 찾아보고 있었는데 이런게 있었네요~
좋은 자료 감사합니다-! :)