Created
December 10, 2012 20:03
-
-
Save voldyman/4252981 to your computer and use it in GitHub Desktop.
Simple Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CyClientService extends Service { | |
public static final String USERNAME = ""; | |
public static final String PASSWORD = ""; | |
public static final String SERVER = ""; | |
private Boolean cont = true; | |
private CyberLoginManager loginManager; | |
@Override | |
public int onStartCommand(Intent intent, int flags, int startId) { | |
String username = intent.getStringExtra(USERNAME); | |
String password = intent.getStringExtra(PASSWORD); | |
String server = intent.getStringExtra(SERVER); | |
loginManager = new CyberLoginManager(server,username, password); | |
initLogin(); | |
return super.onStartCommand(intent, flags, startId); | |
} | |
private Handler mHandler; | |
Runnable liveLoginTask = new Runnable() { | |
@Override | |
public void run() { | |
Result res = loginManager.LiveLogin(); | |
if (res.success && cont) | |
mHandler.postDelayed(this, 180); | |
else { | |
//TODO implement error sending to activity | |
} | |
} | |
}; | |
@Override | |
public IBinder onBind(Intent arg0) { | |
// TODO Auto-generated method stub | |
return(null); | |
} | |
@Override | |
public void onDestroy () { | |
cont = false; | |
mHandler.removeCallbacks(liveLoginTask); | |
} | |
private void initLogin () { | |
Result res = loginManager.Login(); | |
if (res.success) { | |
mHandler.postDelayed(liveLoginTask, 180); | |
} | |
else { | |
//TODO send error to activity | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment