How to prevent theme.dialog from acting to provide external contact?
I have an Activity using the Theme.Dialog style. This is the popup for my quiz, for the wrong answer. But I have a problem. The user can click outside the popup dialog and click on the next question. How can this be prevented? I have disabled the back button and it works fine. In addition, when the user clicks on or outside the pop-up window, it starts counting down the on-time again. My popup stays on for 2500ms. How to prevent this also?
So, basically I don't want to allow click outside of my popup and don't want to reset the delay time when someone taps on the screen.
Here is the popup code:
public class WrongAnswer extends Activity{
MediaPlayer sound;
TextView wrong;
String correctAnswer, correct;
public final int delayTime = 2500;
private Handler myHandler = new Handler();
public void onUserInteraction(){
myHandler.removeCallbacks(closePopup);
myHandler.postDelayed(closePopup, delayTime);
}
private Runnable zatvoriPopup = new Runnable(){
public void run(){
finish();
}
};
@Override
public void onBackPressed() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.wrong);
Bundle extras = getIntent().getExtras();
if(extras !=null) {
tacno = extras.getString("correctAnswer");
}
inicijalizujVarijable();
myHandler.postDelayed(closePopup, delayTime);
}
private void inicijalizujVarijable() {
wrong = (TextView) findViewById(R.id.tvWrong);
wrong.setText("Wrong answer!\nCorrect answer is:\n\n" + correct);
}
}
My activity in manifest:
<activity
android:name="com.myquiz.myquizgame.WrongAnswer"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="com.myquiz.myquizgame.WRONGANSWER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
source to share
If I understand you correctly, this question has already been asked. Here is the answer and according to that you need to call the setter on activity method which will close your activity dialog:
this.setFinishOnTouchOutside(false);
Hope this helps you.
Second, every time the user touches the WrongAnswer action, you start a new pending task and cancel the previous one:
public void onUserInteraction() {
myHandler.removeCallbacks(zatvoriPopup);
myHandler.postDelayed(zatvoriPopup, delayTime);
}
why are you having problems with the timer
source to share