我有2個活動。首次運行應用程序時,我必須在第一次啓動應用程序時打開活動1中的彈出窗口。之後,我想參加活動2並在那裏做一些改變。再次回到活動2,我不想打開彈出窗口。但問題是,每當我回到第一活動彈出窗口是打開的。如何解決這個問題?如何在Android上使用onResume()?
這是我的代碼。
db = dbhelper.getReadableDatabase();
String query = "SELECT * FROM Inspector where ActiveStatus= '1' AND FollowFlag ='1'";
Cursor cursor = db.rawQuery(query, null);
if (cursor.moveToFirst())
{
do
{
String strInspectoreName = cursor.getString(cursor.getColumnIndex("Inspector_name"));
String strInspectorId = cursor.getString(cursor.getColumnIndex("Inspector_Id"));
if(!strInspectorId.equals(str_LoginUserId))
{
inspector_ArrayList.add(strInspectoreName);
Log.e("Post ", " Total FollowUp Users !!!" + strInspectoreName);
}
} while (cursor.moveToNext());
}
cursor.close();
db.close();
int countFollowUp = inspector_ArrayList.size();
Log.e("Post ", " Total countFollowUp Users !!!" + countFollowUp);
if(countFollowUp == 0)
{
final Dialog dialog = new Dialog(CustomActionActivity.this);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
dialog.setContentView(R.layout.custom_dialog_layout);
Button followStart = (Button) dialog.findViewById(R.id.button_FollowStart);
followStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(CustomActionActivity.this, Filter_Screen.class);
startActivity(i);
}
});
Button dismissButton = (Button) dialog.findViewById(R.id.button_Dissmiss);
dismissButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
這裏是我的onResume()在活動第一次
@Override
protected void onResume()
{
super.onResume();
Log.e(" Activity ", " Resume !!! ");
Log.e("From ", " Filter 222");
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
booleanValue_one = sharedPreferences.getBoolean("LISTVIEW_EVENT_ONE", false);
booleanValue_two = sharedPreferences.getBoolean("LISTVIEW_EVENT_TWO", false);
Log.e("", "booleanValue_one=" + booleanValue_one + " booleanValue_two=" + booleanValue_two);
if (booleanValue_one == true || booleanValue_two == true)
{
GetAllActivityDetails task = new GetAllActivityDetails();
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
Log.e(" booleanValue_one "," = " + booleanValue_one +" After completing async task !!!!");
updatedDownLoadStatus();
}
if (booleanValue_one == false && booleanValue_two == false)
{
populateList();
}
}
這裏是我的第二個活動onBackPressed() - >去第一個活動
@Override
public void onBackPressed() {
super.onBackPressed();
Intent a = new Intent(Filter_Screen.this, CustomActionActivity.class);
a.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(a);
overridePendingTransition(R.anim.slide_in_bottom, R.anim.slide_out_bottom);
}
onBackPressed()方法不啓動活動。 –
然後如何返回第一個活動。 –
@override public void onBackPressed(){super.onBackPressed(); overridePendingTransition(R.anim.slide_in_bottom,R.anim.slide_out_bottom); } –