你们需要把阿斯辛卡·塔克作为固定的内产阶级,并拥有一个提及你活动的财产。 然后,你可以直接要求你们的活动,就像你要求点名一样。
你们必须知道的一个问题是,你现在必须小心,明确提及你在任何停电背上的活动,否则你就会发出通告,这将造成记忆泄露。
My pattern is to have another basic Java object, usually another private static class in the Activity which I call "StateHolder" and its my gateway for handling the AsyncTask stuff, such as initializing it and clearing it out (setting to NULL) and cancelling any tasks in progress during rotation changes. In your callback for "onRetainNonConfigurationInstance" you can pass use your StateHolder as your marshalled object.
这里有一些粗略的法典:
private static class GetConnectionsStatusTask extends AsyncTask {
private BoothActivity mActivity;
private Exception mReason;
public GetConnectionsStatusTask(BoothActivity activity) {
super();
mActivity = activity;
}
public void setActivity(BoothActivity activity) {
mActivity = activity;
}
@Override
protected void onPreExecute() {
if(mActivity != null) {
mActivity.startProgressBar("Loading", "Please wait");
}
}
@Override
protected Connections doInBackground(Void... values) {
try {
App app = (App)mActivity.getApplication();
return(app.getApp().userConnections());
}catch(Exception e) {
mReason = e;
return(null);
}
}
@Override
protected void onPostExecute(Connections status) {
super.onPostExecute(status);
if(mActivity != null) {
mActivity.completedConnectionsStatusCheck(status, mReason);
}
}
}
private static class StateHolder {
private GetConnectionsStatusTask connectionsTask;
public void cancelTasks() {
if (connectionsTask != null) {
connectionsTask.setActivity(null);
connectionsTask.cancel(true);
connectionsTask = null;
}
}
public void setActivityForTasks(BoothActivity activity) {
if (connectionsTask != null) {
connectionsTask.setActivity(activity);
}
}
public void startConnections(BoothActivity activity) {
if(mIsConnectionsChecking == false) {
mIsConnectionsChecking = true;
connectionsTask = new GetConnectionsStatusTask(activity);
connectionsTask.execute();
}
}
}
然后,在Pause 我有这样的法典:
if(mStateHolder != null) {
mStateHolder.cancelTasks();
}
在座各位可以重新接纳你们的国家。
Object retained = getLastNonConfigurationInstance();
if(retained != null && retained instanceof StateHolder) {
mStateHolder = (StateHolder) retained;
mStateHolder.setActivityForTasks(this);
} else {
mStateHolder = new StateHolder();
}
这也将使贵国重新开始目前的活动,以便你能够重新建立任何“倡议”植被,如进展限制更新等。
采用这种模式,你实际上可以承担同侪任务,处理轮流变化,而进展则不必重新开始。