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

  • Home
  • SEARCH
  • 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 8950443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:27:25+00:00 2026-06-15T13:27:25+00:00

calling alarm: Log.e(call: , calling alarm); sessionForPost = Session.getActiveSession(); if(sessionForPost != null) Log.e(session: ,

  • 0

calling alarm:

        Log.e("call: ", "calling alarm");

        sessionForPost =  Session.getActiveSession();
        if(sessionForPost != null)
            Log.e("session: ", "not null");
        else
            Log.e("session: ", "null");

        Alarm alarm = new Alarm();
        alarm.SetAlarm(getActivity().getApplicationContext());

alarm manager class:

public static class Alarm extends BroadcastReceiver 
{    
    static String victimId = null;
    static Context context;

    public Alarm(Context context){
        Alarm.context = context;
    }
    public Alarm(){
        if(sessionForPost != null){
            Log.e("Alarm session: ", "not null");
        }
        else
            Log.e("Alarm session: ", "null");

    }


     @SuppressLint("Wakelock")
    @Override
     public void onReceive(final Context context, final Intent intent) 
     {   
         PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
         PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "my wak up lo");
         wl.acquire();

         if(sessionForPost != null)
            Log.e("onReceive session: ", "not null");
        else
            Log.e("onReceive session: ", "null");

         postFromAlarm(sessionForPost);


         Toast.makeText(context, "Alarm !!!!!!!!!!", Toast.LENGTH_LONG).show(); // For example

         wl.release();

     }

 public void SetAlarm(Context context)
 {
     if(sessionForPost != null)
            Log.e("SetAlarm session: ", "not null");
        else
            Log.e("SetAlarm session: ", "null");

     Alarm.context = context;
     Log.e("setalarm: ", "i am here");
     AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
     Intent i = new Intent(contextForPost.getApplicationContext(), Alarm.class);
     PendingIntent pi = PendingIntent.getBroadcast(Alarm.context, 2, i, PendingIntent.FLAG_CANCEL_CURRENT);
     am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ 1000 * 10, pi); // Millisec * Second * Minute
 }

 public void CancelAlarm(Context context)
 {
     Intent intent = new Intent(context, Alarm.class);
     PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
     AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
     alarmManager.cancel(sender);
 }
}

postFromAlarm() method:

public static void postFromAlarm(Session session){
    String victimId;
    if(flag){
     Log.e("flag: ", "true");
    }else{
     Log.e("flag: ", "false");
    }
    if(Session.getActiveSession() != null)
        Log.e("session: ", "not null");
    else
        Log.e("session: ", "null");

    if(Session.getActiveSession() != null){
     Log.e("onRecieve: ", "i am here");

    Bundle postParams = new Bundle();
        postParams.putString("message", msg);

        Request.Callback callback= new Request.Callback() {
            public void onCompleted(Response response) {
                JSONObject graphResponse = response
                                           .getGraphObject()
                                           .getInnerJSONObject();
                String postId = null;
                try {
                    postId = graphResponse.getString("id");
                } catch (JSONException e) {
                    Log.i(TAG,
                        "JSON error "+ e.getMessage());
                }
                FacebookRequestError error = response.getError();
                if (error != null) {
                    Toast.makeText(contextForPost,
                         error.getErrorMessage(),
                         Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(contextForPost, 
                             postId,
                             Toast.LENGTH_LONG).show();
                }
                //Log.e("Ashchi to: ",error.getErrorMessage());
            }
        };
        Log.e("Ashchi to2: ","poststory class");
        if(friendId != null){
            victimId = friendId;
        }else{
            victimId = user_ID;
        }
        Request request = new Request(Session.getActiveSession(), victimId+"/feed", postParams, 
                              HttpMethod.POST, callback);

        RequestAsyncTask task = new RequestAsyncTask(request);

        task.execute(); 
        flag = true;
}

}

now the LogCat when i call SetAlarm() :

12-06 14:55:53.757: call: calling alarm
12-06 14:55:53.767: session: not null
12-06 14:55:53.787: Alarm session: not null
12-06 14:55:53.787: SetAlarm session: not null
12-06 14:55:53.787: setalarm: i am here

and then when the alarm fire LogCat give me:

12-06 14:56:04.437: Alarm session: null
12-06 14:56:04.457: onReceive session: null
12-06 14:56:04.457: flag: false
12-06 14:56:04.487: session: null

my manifest for alarm manager:

......
 <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
......
<application
.....
<receiver  android:process=":remote" android:name="com.timelystatusupdater.MyLoggedInFragment$Alarm"></receiver>
.....

as you can see, when i call the alarm and check out the Session, it is not null. But when the alarm fire the session is turning into null. what is the problem. remember sessionForPost is static global variable. how can i prevent session to be turning null

N.B: my alarm class is an inner static class.
the alarm is firing after 10 second when the alarm is set

  • 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-15T13:27:26+00:00Added an answer on June 15, 2026 at 1:27 pm

    Tactically, delete android:process=":remote", and things may work better.

    However, more generally, your process may be terminated in between invocations of AlarmManager, if your app is in the background. This is perfectly normal and usually is what the user wants. Your code needs to handle this situation. Static data members are a cache, nothing more — anything that needs to survive a process termination needs to be stored persistently (e.g., database, file).

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

Sidebar

Related Questions

I have a alarm manager which is calling an activity class named ScheduleAlert. public
Calling the WriteObject Method from a background thread is not possible! Is there a
Calling getActionBar returns null . This has been frequently reported so I've made sure
Calling channel.position on an ENTER_FRAME event, I notice that it's not being updated every
Calling the function MakeTree(4, gameboard) does not work properly, it only prints out the
Hi i am new to android i am developing alarm application for that i
I have created a Alarm using AlarmManager. Intent intent = new Intent(MyApp.this,NotificationMessage.class); PendingIntent sender
Calling TextView.setTextSize() is working abnormally. Right after the call to setTextSize if we get
Calling setBackgroundDrawable before showing the PopupWindow works fine. But when I call it after
I have a startApplicationService method in an activity. Therefore I have an alarm manager.

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.