我想知道是否有辦法通過在您想離開的活動外提供訂單來移動當前活動。如何從一項活動轉移到另一項活動android
我告訴你什麼是我的了:
這裏是我的閃屏活動:
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
SQLHelper sqlHelper = new SQLHelper(this);
InfosModel infos = sqlHelper.getInfos();
RequestModel request = new RequestModel();
if (infos.getToken().length() == 0){
request.setType("password");
new OAuthHelper().execute(request);
}
}
}
這裏是我的OAuthHelper:
public class OAuthHelper extends AsyncTask<RequestModel, Void, TokenModel> {
public OAuthHelper(){
}
@Override
protected void onPreExecute(){
}
@Override
protected void onPostExecute(TokenModel models){
if (models == null){
Log.i("infos", "You have no internet connection or the server is unreachable !");
}
else{
Log.i("infos", "request's done with success !");
}
}
@Override
protected TokenModel doInBackground(RequestModel... request) {
try
{
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://api.listopresto.com/oauth/token");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
if (request[0].getType() == "password"){
/* Some Params */
}
else{
return (null);
}
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httppost);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String s = reader.readLine();
Log.i("infos", s);
Gson gson = new Gson();
TokenModel tokenObj;
tokenObj = gson.fromJson(s, new TypeToken<TokenModel>(){}.getType());
return (tokenObj);
} catch (ClientProtocolException e) {
Log.i("infos", "first");
return (null);
} catch (IOException e) {
Log.i("infos", "second");
return (null);
}
}
catch (Exception e){
Log.i("infos", "third");
return (null);
}
}
}
如果我粘貼spashscreen類中幫助我的,當然我可以移動到另一個活動,但這是一個助手,我的意思是我必須從別的地方再次使用它,我當然不想再通過我的splashScreen ...
...我想給在postExecute方法爲了我想從我的濺射屏幕移動到好的,這取決於我的答案從服務器得到什麼..
是有辦法做到這一點?
謝謝你!! ;)
http://developer.android.com/reference/android/os/Handler.html嘗試處理 – CoolMonster