I want to show Dialog when I'm at home screen after 10s,
and I modify my Theme to Theme.Dialog,
And now,I successfully pop it up when I pressed Back Key to home screen.
But my question is that after I pressed Home Key and go to home screen,
dialog won't pop up after 10s ,
However,when I open my application,
I found that it has popped up there.
So,can anybody told me how to solve this problem?
this is my code(I use two activities):
First Activity:
public class MainActivity extends Activity {
private Button bt_dialog;
AlertDialog.Builder builder;
AlertDialog mDialog;
Intent i = new Intent();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt_dialog = (Button) findViewById(R.id.button1);
i.setClass(MainActivity.this, DialogActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//click button and show the dialog after 10s
bt_dialog.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(final View view) {
CountDownTimer dlgCountDown;
dlgCountDown = new CountDownTimer(10000, 1000){
public void onTick(long millisUntilFinished) {
}
public void onFinish(){
startActivity(i);
}
}.start();
}
});
}
Second Activity:
public class DialogActivity extends Activity{
AlertDialog.Builder builder;
AlertDialog mDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_dialog);
String dialogText = "dialog text";
TextView txt = (TextView) findViewById(R.id.textView1);
txt.setText(dialogText);
Button dismissbutton = (Button) findViewById(R.id.button1);
dismissbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DialogActivity.this.finish();
}
});
}
And this is my Manifest code:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.testdialog.MainActivity"
android:theme="@android:style/Theme"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.testdialog.DialogActivity"
android:theme="@android:style/Theme.Dialog">
</activity>