Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- autostart.java
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.preference.PreferenceManager;
- import android.util.Log;
- public class autostart extends BroadcastReceiver
- {
- public void onReceive(Context arg0, Intent arg1)
- {
- Intent intent = new Intent(arg0,service.class);
- arg0.startService(intent);
- Log.i("Autostart", "started");
- }
- }
- --------------------------------------
- service.java
- import android.app.Service;
- import android.content.Intent;
- import android.os.IBinder;
- import android.util.Log;
- import android.widget.Toast;
- public class service extends Service
- {
- private static final String TAG = "MyService";
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
- public void onDestroy() {
- Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
- Log.d(TAG, "onDestroy");
- }
- @Override
- public void onStart(Intent intent, int startid)
- {
- Intent intents = new Intent(getBaseContext(),hello.class);
- intents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intents);
- Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
- Log.d(TAG, "onStart");
- }
- }
- ----------------------------------------------------------------------------
- hello.java
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.Toast;
- public class hello extends Activity
- {
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Toast.makeText(getBaseContext(), "Hello........", Toast.LENGTH_LONG).show();
- }
- }
- --------------------------
- manifest.java is as follow
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.testing1"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="8" />
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <receiver android:name=".autostart"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- </receiver>
- <activity android:name=".hello"></activity>
- <service android:enabled="true" android:name=".service" />
- </application>
- </manifest>
- -----------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement