Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9191481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:41:39+00:00 2026-06-17T20:41:39+00:00

i created a program that will ring an alarm if it received a message

  • 0

i created a program that will ring an alarm if it received a message even when phone is locked. when the phone rings, it will show dismiss button to stop the alarm, but my code just shows the dismiss button and disappears quickly leaving me with no option on how to stop the alarm. please help me with this code. thanks for help in advance

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.receiverinterface);
    unlockScreen();
    alertDialogBuilder = new AlertDialog.Builder(
            context);
    alertDialogBuilder.setTitle("Alarm");
            alertDialogBuilder
            .setMessage("Stop Alarm")
            .setCancelable(false)
            .setPositiveButton("Dismiss", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    Ringtone r = EAlarmReceiver.r;
                    r.stop();
                    Toast.makeText(context.getApplicationContext(), "Alarm Stopped", Toast.LENGTH_LONG).show();
                    if(EAlarmReceiver.sms.length() > 10)
                    {
                        Intent openInterface = new Intent("proj.receiver.VIEWMESSAGE");
                        openInterface.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(openInterface);
                    }
                    else
                    {
                        Intent openInterface = new Intent("proj.receiver.RECEIVERINTERFACE");
                        openInterface.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(openInterface);
                    }
                }
            });
            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();
            // show it
            alertDialog.show();
}// end oncreate()

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

//unlock screen
public void unlockScreen() {
    //make the activity show even the screen is locked.
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            + WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            + WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:41:40+00:00Added an answer on June 17, 2026 at 8:41 pm

    Try this code after removing finish() from onPause(). post complete code too.

    Edit :- As you said removing finish worked for you, here is solution of your second question.

    1) Complex and temporary solution :- try to add a boolean variable, which u should set to true on action taken on AlertDialog, and if it is true in onResume , finish ur activity. OnResume calls each time u comes back to ur activity.

    2) But if i were at ur place, i would have followed below approach.

    Create a layout looks like alert Dialog. and setup Activity theme as Dialog in activity declaration in manifest, it will open ur activity as dialog. hence u need not to create an AlertDialog to handle action, u can add buttons for dismiss and all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a server program that will be started as root. After it is
I am contemplating writing a program that will move some newly created dirs to
I created a program that will use a dynamic array by using pointer to
I've created a program that will allow users to log in and enter the
I have created a program that wehn the calculate button is pressed, an average
I've already created a program that will display x number of rows and repeat
I created a Java program that will process files using a C++ program. This
I am trying to create a program that will get data directly from socket
I am trying to create a program that will be passed input data from
I am trying to create a program that will do some simple calculations, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.