2015-07-11 42 views
1

我的应用程序,从GetActivity活动的MySQL中获取数据,并保存在mysqlite和创造的通知现在,我多么希望我的应用程序运行自动化,并开始GetActivity在后台获取数据自动启动和充分利用网络数据背景

+1

您的代码是哪里? –

+0

谢谢,问题解决了 – sadegh

回答

3

你我们想看看Services这是在Android的后台运行的线程。从那里你可以从你的SQL数据库加载你的数据。

要照顾自动启动,您需要查看BroadcastReceivers,特别是BOOT_COMPLETED接收器。

2

首先你需要添加这个。

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);*/ 
    } 
} 

其次,你需要这个帮助添加此清单中

 <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> 

希望你。享受

http://smrnatore08.wix.com/smr-it-ltd