0

In my application am going to show the dialog in particular time interval,for the time interval am using runnable method in separate class.

My runnable method class

public class Timeout_function{

Handler mHandler;
Activity activity;

public Timeout_function(Activity activity,Handler mHandler) {
    super();
    this.activity = activity;
    this.mHandler = mHandler;

}

Runnable first_Task = new Runnable() {
    public void run() {


        dialog = new Dialog(activity);
        if(isShown){
            dialog.dismiss();
            dialog_msgs = "Your order is going to Expired. You want to continue.";
            dialogs();
        }
        else
        {
            dialog_msgs = "Your order is going to Expired. You want to continue.";
            dialogs();
        }

        mHandler.removeCallbacks(first_Task);
    }
    }
};

Runnable second_Task = new Runnable() {
    public void run() {





                dialog = new Dialog(activity);
                if(isShown){
                    dialog.dismiss();
                    dialog_msgs = "Your order is going to Expired. You want to continue.";
                    dialogs();
                }
                else
                {
                    dialog_msgs = "Your order is going to Expired. You want to continue.";
                    dialogs();
                }

            mHandler.removeCallbacks(second_Task);

    }
};

// just as an example, we'll start the task when the activity is started
public void onStart() {

    Time_out = 1;
    mHandler.postDelayed(first_Task, 2 * 30 * 1000);
}

public void onStart_extend(){
    mHandler.postDelayed(second_Task, 1 * 30 * 1000);
}

// at some point in your program you will probably want the handler to stop (in onStop is a good place)
public void onStop() {

        mHandler.removeCallbacks(first_Task);   
        mHandler.removeCallbacks(second_Task);

}


//Error Messages

public void dialogs(){

Typeface font = Typeface.createFromAsset(activity.getAssets(), "fonts/CALIBRI.TTF");;
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
dialog.setContentView(R.layout.dialog_timeout);
dialog.setCancelable(false);
isShown=true;

TextView tv_msg = (TextView)dialog.findViewById(R.id.dialog_texts);
tv_msg.setTypeface(font);
tv_msg.setText(""+dialog_msgs);

Button no =(Button)dialog.findViewById(R.id.dialog_no);
no.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub

        dialog.dismiss();
        order_list_remove();
        Time_out = 0;
        //onStop();
    }
});

Button yes =(Button)dialog.findViewById(R.id.dialog_yes);
yes.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub

        onStart_extend();
        dialog.dismiss();
    }
});
dialog.show();
}
}

I have activity A,B,C am going to start this runnable method only in activity b like

Timeout_function time_out ;
Handler mHandler;
mHandler = new Handler();
time_out = new Timeout_function(activityb.this, mHandler);
time_out.onStart();

this way,i want show the dialog in certain interval of time.If user in activity A means show the dialog in Activity A same as like in B and c,I don't know how to show the dialog in all activity.Can any one one know please help me to solve this problem.

Yugesh
  • 4,030
  • 9
  • 57
  • 97

1 Answers1

0
  1. use a service to maintain the dialog showing in interval
  2. Use an dialog activity. you can create it same as activity. use following in manifest

        android:excludeFromRecents="true"
        android:launchMode="singleInstance"
        android:taskAffinity=""
        android:theme="@android:style/Theme.Dialog"
    
  3. now from service when on interval start the dialog activity like regular activity.

stinepike
  • 54,068
  • 14
  • 92
  • 112