From a login activity while pressing a button I run the following service:
public class PlayerService extends Service{
private StorageApi api;
private String user, password, host = "****";
private Intent i;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
i = intent;
user = intent.getStringExtra("User");
password = intent.getStringExtra("Pass");
new connectStorage().execute();
return startId;
}
@Override
public void onDestroy() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
private class connectStorage extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
try {
api = DefaultClientFactory.create(host, user, password);
Log.i("TEST",""+api.getUserInfo());
return true;
} catch (StorageApiException e) {
e.printStackTrace();
Log.i("TEST", "" + e.getMessage());
return false;
}
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if(result == false){
// progressGenerator.finnish(btnSignIn);
// btnSignIn.setProgress(-1);
Toast.makeText(getApplicationContext(), "Invalid E-mail or Password !", Toast.LENGTH_SHORT).show();
}
else
{
Intent myIntent = new Intent(PlayerService.this, musicPlayer.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(myIntent);
}
}
}
}
As you see in Asynctask after I connect to api I use
Log.i("TEST",""+api.getUserInfo());
getUserInfo method and I get informations like Username, Name, Last Name, E-mail etc...
After doing this this, onPostExecute I switch activity to another screen. My question is, how I can use the API object after connection was initialized and for example get user info on another activity ?