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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:33:46+00:00 2026-06-16T00:33:46+00:00

I’m currently developing an application and I’m using this post code to get the

  • 0

I’m currently developing an application and I’m using this post code to get the GPS lock.
What is the simplest and most robust way to get the user's current location on Android?

It works like a charm! It chooses very well for my requirements.
What I’m now trying to do is triggering this method every 10 minutes to get gps signal and saving it in a txt file.
My problem is I’ve been unable to understand how AlarmManager works as it calls AFAIK the onCreate() method of the activity.
How can I make an AlarmManager call an specific method every 10 minutes in the background even with the telephone sleeping?

Edit 2:
I’ve used the code provided by A–C but for some reason the alarm isn’t calling the method on my class AlarmBroadcastReceiver.
This is my method in the MainActivity.

    Intent intent = new Intent (this, AlarmBroadcastReceiver.class);
    PendingIntent pendIntent = PendingIntent.getBroadcast(this, 1,  intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) getSystemService (Context.ALARM_SERVICE);
    alarmManager.cancel(pendIntent); //cancel if active already

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis()+4000,
            4000, pendIntent);

and in the AlarmBroadcastReceiver class.

    public class AlarmBroadcastReceiver extends BroadcastReceiver{
public float accuracy;
public double latitude;
public double longitud;
public static boolean Activado=false;
public void onReceive(Context context, Intent intent) {
Log.d("AlarmManager", "Method onReceiveCalled");
    }

What I’m doing wrong?

  • 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-16T00:33:47+00:00Added an answer on June 16, 2026 at 12:33 am

    Unless the Activity‘s method is static and is running in the same process, you don’t run a single method via Intents.

    You could pass of extras to your Activity through its Intent that specifies what it should be doing and in onCreate() take care of the logic for that.

    You could also try to put the functionality directly in the AlarmReceiver, since that’s as local as you can go for that class.

    So of course, you could replace the Activity with a background service that handles this.

    Lastly, since you’re saving to a text file every 10 mins, you could potentially make a class specifically for saving. All you do is call that class with the String and Context (I’m assuming file operations need a Context) from wherever you need. This can be integrated with your GPS code, most likely with another constructor so the GPS class knows it’s specifically getting the location and saving it.

    Here is an example of how the alarm setup could look like:

        Intent intent = new Intent (this, AlarmBroadcastReceiver.class);
        PendingIntent pendIntent = PendingIntent.getBroadcast(this, 1,  intent, PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager alarmManager = (AlarmManager) getSystemService (Context.ALARM_SERVICE);
        alarmManager.cancel(pendIntent); //cancel if active already
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis()+600000,
                600000, pendIntent);
    

    So you need an Intent, it gets turned into a PendingIntent. Then you need to get an AlarmManager instance. The last line of my code registers the alarm 10 minutes ahead of time with a repeat of 10 minutes. AlarmManager.RTC_WAKEUP forces the phone to wake up to execute the alarm.

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

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.