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 8923095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:01:33+00:00 2026-06-15T07:01:33+00:00

I want to display an alert when a sms is received, so my idea

  • 0

I want to display an alert when a sms is received, so my idea is to start a new activity that launch the alertdialog.

My service starts with no problem, and starts receiver as well..

I can receive sms and display toast alerts fine.. but i’d like to show a custom alertdialog instead.

This is the activity that starts my service (ServiceExampleActivity ):

public class ServiceExampleActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btnStartService = (Button) findViewById(R.id.btnStart);
        Button btnStopService = (Button) findViewById(R.id.btnStop);

        btnStartService.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                StartMyService();
            }
        });

        btnStopService.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                StopMyService();
            }
        });          

    }

    private void StartMyService() {
        Intent myServiceIntent = new Intent(this, ServiceTest.class);
        startService(myServiceIntent);
    }

    private void StopMyService() {
        Intent myServiceIntent = new Intent(this, ServiceTest.class);
        stopService(myServiceIntent);
    }        
}

This is my Service (ServiceTest):

public class ServiceTest extends Service {

    private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
    private BroadcastReceiver myBroadcastReceiver = null;

    @Override
    public void onCreate() {
        super.onCreate();

        final IntentFilter theFilter = new IntentFilter();
        theFilter.addAction(ACTION);

        this.myBroadcastReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {

                StartDialogActivity(context, intent);

            }
        };

        this.registerReceiver(myBroadcastReceiver, theFilter);
    }

    @Override
    public IBinder onBind(Intent arg) {
        return null;
    }

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);

        Log.d("ServiceTest", "Started");
        Toast.makeText(this, "Service started...", 3000).show();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        unregisterReceiver(myBroadcastReceiver);
        Toast.makeText(this, "Service destroyed...", 3000).show();
    }

    private void StartDialogActivity(Context context, Intent intent) {
        Intent dlgIntent = new Intent(context, DialogActivity.class);               
        dlgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);      
        context.startActivity(dlgIntent);   
    }
}

And this is the activity i want to launch to display the alertdialog normally..

public class DialogActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog);       

    }
}

When it tries to start the activity, the app crashes..
Can you tell me were is the error..??

  • 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-15T07:01:35+00:00Added an answer on June 15, 2026 at 7:01 am

    Like this, you want start activity from service

    Intent dlgIntent = new Intent(context, DialogActivity.class);
    dlgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getApplication().startActivity(dlgIntent );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to display an alert at first launch of application, and that alert
I want to display an alert from a service and I don't care what
I want to display an alert box multiple times with a button click event
I want to display error message or alert message after checking the condition. here
I want to display script errors in a popup alert instead of showing them
I want to display a form in a Div, in alert box. How would
I want to display an alert in every time when the user change the
In my application I want to display CLLocationManager alert( App name would you like
I want to display the alert box but for a certain interval. Is it
I want to display an alert box showing a message with PHP. Here is

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.