Saturday, July 11, 2015

android: Autostart application and Getting data from internet / mysql in Background

First you need to add this.
public class MyBroadcastreceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        ///// Add your Background Service that Sync your data from database or internet//////////
        //// I do the same work it fine work to me.///////
        context.startService(new Intent(context, service_ReloadSqlDB.class));

       /* Intent i = new Intent(context, MainActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);*/
    }
}
Secondly you need to add this in manifest
        <receiver
            android:name="com.b2mtech.wrapper.MyBroadcastreceiver"
            android:enabled="true"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
You can Also visit bellow link , Hope this help you. Enjoy

No comments:

Post a Comment