Android Service Example
Ex9Activity.java
package com.bipin.rupadiya.Ex9;
import prg.Ex9.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Ex9Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent();
intent.setClassName("prg.Ex9", "prg.Ex9.MyService");
startService(intent);
setContentView(R.layout.main);
}
}
import prg.Ex9.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Ex9Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent();
intent.setClassName("prg.Ex9", "prg.Ex9.MyService");
startService(intent);
setContentView(R.layout.main);
}
}
MyServic.java
package com.bipin.rupadiya.Ex9;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class MyService extends Service
{
private Timer timer = new Timer();
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
Log.i("MyService", "Service Created...");
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Log.i("MyService", "Service Started...");
timer.schedule(new mainTask(), 1000 * 10);
}
private class mainTask extends TimerTask
{
public void run()
{
Intent in = new Intent(MyService.this, AlertActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(in);
}
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.i("MyService", "Service Destroyed...");
}
}
import java.util.Timer;
import java.util.TimerTask;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class MyService extends Service
{
private Timer timer = new Timer();
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
Log.i("MyService", "Service Created...");
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Log.i("MyService", "Service Started...");
timer.schedule(new mainTask(), 1000 * 10);
}
private class mainTask extends TimerTask
{
public void run()
{
Intent in = new Intent(MyService.this, AlertActivity.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(in);
}
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.i("MyService", "Service Destroyed...");
}
}
AlertActivity.java
package com.bipin.rupadiya.Ex9;
import android.app.Activity;
import android.os.Bundle;
public class AlertActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alert);
}
}
import android.app.Activity;
import android.os.Bundle;
public class AlertActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alert);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="36dp"
android:layout_y="199dp"
android:text="www.BipinRupadiya.com"
android:textAppearance="?android:attr/textAppearanceLarge" />
</AbsoluteLayout>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="36dp"
android:layout_y="199dp"
android:text="www.BipinRupadiya.com"
android:textAppearance="?android:attr/textAppearanceLarge" />
</AbsoluteLayout>
alert.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="36dp"
android:layout_y="199dp"
android:text="welcome to new task"
android:textAppearance="?android:attr/textAppearanceLarge" />
</AbsoluteLayout>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="36dp"
android:layout_y="199dp"
android:text="welcome to new task"
android:textAppearance="?android:attr/textAppearanceLarge" />
</AbsoluteLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bipin.rupadiya.Ex9"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Ex9Activity"
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="com.bipin.rupadiya.Ex9.MyService"></service>
<activity android:name="com.bipin.rupadiya.Ex9.AlertActivity"></activity>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bipin.rupadiya.Ex9"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Ex9Activity"
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="com.bipin.rupadiya.Ex9.MyService"></service>
<activity android:name="com.bipin.rupadiya.Ex9.AlertActivity"></activity>
</application>
</manifest>
Labels:
Android,
Mobile Computing
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
0 comments:
Post a Comment