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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:32:03+00:00 2026-05-26T06:32:03+00:00

I was following this tutorial for displaying a notification on an Android device .

  • 0

I was following this tutorial for displaying a notification on an Android device. When I ran the application on the device, an icon appeared on the status bar (as usually it appears on Android device) which is absolutely perfect. But just out of curiosity I wanted to know that can I display an alert or some view with few details when device receives a notification? I want to implement this concept in my next application.
Some sample would greatly help me.

  • 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-05-26T06:32:03+00:00Added an answer on May 26, 2026 at 6:32 am

    A typical kind of pattern would be for you to register a certain part of your application to “receive”, or listen for, specific intents. This way, your application can wake up at any arbitrary point in time, look at the calling intent, and decide how to handle it (be it starting the full application, displaying a dialog, or something else). One good thing that goes along with this is to use the AlarmManager to set an alarm that will fire and wake up your application in the future (periodic updates).

    Does this answer your question? I’ve done something like this in my application and I can help you with the code if you like.

    EDIT to implement this you would make a java class that extends either BroadcastReceiver or IntentService (depending on if you want the class to run on the ui thread or as a service respectively). In my example below, I have defined my own intent action key, but typically you would check the action with intent.getAction():

    public class QueryService extends IntentService {
    public final static String SERVICE_NAME = "QueryService";
    
    // incoming flags
    public final static String FLAG_ACTION = "R_ACTION";
    public final static String FLAG_EVENTS_RETURNED = "R_EVENTS";
    public final static String FLAG_EVENTS_ARCHIVED_RETURNED = "R_EVENTS_ARCH";
    public final static String FLAG_SHARED_PREFERNCES_RETURNED = "R_PREFS";
    
    // outgoing flags
    public final static String RETURN_EVENTS = "RETURN_E";
    public final static String RETURN_EVENTS_ARCHIVED = "RETURN_E_A";
    public final static String RETURN_SHARED_PREFS = "RETURN_S_P";
    
    public QueryService() {
        super(SERVICE_NAME);
    }
    
    protected void onHandleIntent(Intent intent) {
        String rAction = intent.getStringExtra(FLAG_ACTION);
        boolean rEvents = intent.getBooleanExtra(FLAG_EVENTS_RETURNED, true);
        boolean rEventsArchived = intent.getBooleanExtra(FLAG_EVENTS_ARCHIVED_RETURNED, true);
        boolean rSharedPrefs = intent.getBooleanExtra(FLAG_SHARED_PREFERNCES_RETURNED, true);
    
        if(rAction == null){
            Log.e(SERVICE_NAME, "no return action specified, exiting...");
            return;
        }
    
        Log.i(SERVICE_NAME, "Caller: " + rAction);
    
        DroidTaskApplication app = (DroidTaskApplication)getApplicationContext();
    
        Intent resultsIntent = new Intent(rAction);
        // TODO assembling events / archived events from a database needs
        // a function that gets the complete event instead of just its headers
    
        // assemble event objects and insert them
        if(rEvents){
            List<Event> liteEvents = app.edo.getAllEvents();
            if(liteEvents != null){
                for(Event e : liteEvents){
                    int id = e.getId();
                    e.setAlarms(app.edo.getAlarmsById(id));
                    e.setSubtasks(app.edo.getSubtasksById(id));
                    e.setNotes(app.edo.getNotesById(id));
                }
            }
            resultsIntent.putExtra(RETURN_EVENTS, (Serializable)liteEvents);
        }
        // assemble archived event objects and insert
        if(rEventsArchived){
            List<Event> liteEventsA = app.edo.getAllArchivedEvents();
            resultsIntent.putExtra(RETURN_EVENTS_ARCHIVED, (Serializable)liteEventsA);
        }
        // collect the shared data and send it
        if(rSharedPrefs){
            SharedPreferences prefs = getSharedPreferences(getString(R.string.PREFS_FILE_NAME), MODE_WORLD_READABLE);
            resultsIntent.putExtra(RETURN_SHARED_PREFS, (Serializable)(prefs == null? null : prefs.getAll()));
        }           
    
        Log.i(SERVICE_NAME, "returning results");
    
        // send everything to the caller
        sendBroadcast(resultsIntent);
     }
    
    }
    

    Regardless whether the class is a service or broadcast receiver, you must register it with the application as a “receiver” (meaning it can accept intent broadcasts of some kind); this can be done in Java code or in the Android manifest. An example I use for that service in the manifest is below (albeit my Java class doesn’t care, about the intent action yet):

        <!-- Notification Launcher -->
        <receiver android:name="edu.clarkson.dtask.BK.NotificationReceiver" android:enabled="true">
            <intent-filter>
                <action android:name="edu.clarkson.dtask.BK.NotificationReceiver.DISPATCH_ALARM" />
                <action android:name="edu.clarkson.dtask.BK.NotificationReceiver.CANCEL_ALARM" />
            </intent-filter>
        </receiver>
    

    Different system actions and notifications will be broadcast by the OS when a certain state changes; if you would like to hear about these changes, you register a broadcastreceiver or intentservice the same way as above in the manifest for a different Intent action (such as ACTION_BATTERY_STATE_CHANGED). All the documentation can be found on the android dev site. I hope that will get you started on the right path.

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

Sidebar

Related Questions

I am following this tutorial https://developer.android.com/guide/tutorials/views/hello-tabwidget.html and have completed it. Now I would actually
I've been following this tutorial on how to implement a Silverlight application. The tutorial
I am following this tutorial: http://www.codeproject.com/KB/android/AndroidSQLite.aspx I must be overthinking this SQLite stuff (in
Following this tutorial i'm developing a web application using symfony authentication/authorization architecture. After designing
I've been following this tutorial: http://developer.android.com/resources/tutorials/views/hello-mapview.html but in onTap mContext is throwing a NullPointerException..
I've been following this tutorial (lesson 6) in order to build and deploy a
I'm following this tutorial (seems good) for Rails. After I run ruby script/generate scaffold
I was following this tutorial . I need to use a php file's ouput
I am following this tutorial and I've run the command ruby script\server and successfully
I've been experimenting with ASP.NET MVC and following this tutorial to create the basic

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.