我从onListItemClick Listener开始一个活动,如图所示
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent n = new Intent(ResultQuestionnaireList.this,ShowResult.class);
n.putExtra("title",""+adapter.getItem(position));
startActivity(n);
}
我的问题是每当手机进入睡眠时新的活动关闭,我的应用程序返回旧活动..
请帮忙吗?
更新: 我的第二个活动代码
public class ShowResult extends AppCompatActivity {
ProgressDialog pDialog;
private String URL_GET_Ques = //Myurl;
private String URL_GET_Ques = //Myurl;
private String URL_GET_RES = //Myurl;
private ArrayList<ResultObject> res;
private ArrayList<AtomQuestionnaire> ques;
private int type;
String title= "";
String question= "";
ArrayAdapter<String> spinnerAdapter;
Spinner spinner;
boolean questionReady=false;
int sortt = 1;
Spinner sortSpin ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_result);
Intent n= getIntent();
if(n.hasExtra("title")){
title = n.getStringExtra("title");
}
questionReady=false;
sortSpin = (Spinner)findViewById(R.id.spinnerType);
sortSpin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// your code here
sortt=position;
if(questionReady &&!question.equals("")) {
getExecuter(title, question, type, position);
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
spinner = (Spinner)findViewById(R.id.spinnerQues);
spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, android.R.id.text1);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// your code here
if(questionReady){
question= parentView.getSelectedItem().toString();
type = ques.get(position).getType();
Log.d("type",type+"");
getExecuter(title, question, type, sortt);
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
ques = new ArrayList<AtomQuestionnaire>();
new GetQuestions(title).execute();
}
public void getExecuter(String title ,String question,int type,int sort){
new GetResults( title,question,type,sort).execute();
}
}