Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. Android - Running endless code in Foreground while using the app

Android - Running endless code in Foreground while using the app

Scheduled Pinned Locked Moved Android
androidgraphicslearning
3 Posts 3 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Exoskeletor
    wrote on last edited by
    #1

    Im making an application that i want to have the ability to send report emails with a frequency. daily, weekly or monthly. Now i want those emails to be sent only if the app is running and if the user is using it (in my app you use the mobile as a kiosk, you open the app and leave it running all the time, screen will not close) I have write this code in the MainActivity where if someone has enabled the frequently email feature, the activity will try to send the email (SendStatisticsToEmailBySchedule() will run forever and will use SendStatisticsToEmail() from time to time to send an email):

    public async void SendStatisticsToEmail(string subject, string address, int port, string from, string to, bool useSSL, bool saveDateSent = false, string username = "", string password = "", bool sendNowButtonUsed = false)
    {
    var fileName = System.IO.Path.Combine(
    GetString(Resource.String.Statistics_ExportAllExportPrefix,
    firstResult.ToString("MM-dd-yyyy"),
    DateTime.Today.ToString("MM-dd-yyyy")));

            var message = new MimeMessage();
            message.From.Add(new MailboxAddress(from));
            message.To.Add(new MailboxAddress(to));
            message.Subject = subject + " " + fileName;
    
            var statistics = new Statistics();
            var reportsForXML = statistics.ConvertRecordsForExport(MyData);
            MemoryStream stream = new MemoryStream();
    
            var builder = new BodyBuilder();
            var image = BitmapFactory.DecodeResource(Resources, Resource.Drawable.get\_started);
            byte\[\] imgbyte;
            using (var bitmap = image)
            {
                var streamByte = new MemoryStream();
                bitmap.Compress(Bitmap.CompressFormat.Png, 100, streamByte);
                bitmap.Recycle();
                imgbyte = streamByte.ToArray();
            }
            var imageAttach = builder.LinkedResources.Add(@"get\_started.png", imgbyte);
            imageAttach.ContentId = MimeUtils.GenerateMessageId();
            builder.HtmlBody = string.Format(@"
    

    {1}

    {2}

    {3}

    ", new object[] { imageAttach.ContentId, GetString(Resource.String.EmailExportSettings_MessageBodyLine1), GetString(Resource.String.EmailExportSettings_MessageBodyLine2), GetString(Resource.String.EmailExportSettings_MessageBodyLin

    N 1 Reply Last reply
    0
    • E Exoskeletor

      Im making an application that i want to have the ability to send report emails with a frequency. daily, weekly or monthly. Now i want those emails to be sent only if the app is running and if the user is using it (in my app you use the mobile as a kiosk, you open the app and leave it running all the time, screen will not close) I have write this code in the MainActivity where if someone has enabled the frequently email feature, the activity will try to send the email (SendStatisticsToEmailBySchedule() will run forever and will use SendStatisticsToEmail() from time to time to send an email):

      public async void SendStatisticsToEmail(string subject, string address, int port, string from, string to, bool useSSL, bool saveDateSent = false, string username = "", string password = "", bool sendNowButtonUsed = false)
      {
      var fileName = System.IO.Path.Combine(
      GetString(Resource.String.Statistics_ExportAllExportPrefix,
      firstResult.ToString("MM-dd-yyyy"),
      DateTime.Today.ToString("MM-dd-yyyy")));

              var message = new MimeMessage();
              message.From.Add(new MailboxAddress(from));
              message.To.Add(new MailboxAddress(to));
              message.Subject = subject + " " + fileName;
      
              var statistics = new Statistics();
              var reportsForXML = statistics.ConvertRecordsForExport(MyData);
              MemoryStream stream = new MemoryStream();
      
              var builder = new BodyBuilder();
              var image = BitmapFactory.DecodeResource(Resources, Resource.Drawable.get\_started);
              byte\[\] imgbyte;
              using (var bitmap = image)
              {
                  var streamByte = new MemoryStream();
                  bitmap.Compress(Bitmap.CompressFormat.Png, 100, streamByte);
                  bitmap.Recycle();
                  imgbyte = streamByte.ToArray();
              }
              var imageAttach = builder.LinkedResources.Add(@"get\_started.png", imgbyte);
              imageAttach.ContentId = MimeUtils.GenerateMessageId();
              builder.HtmlBody = string.Format(@"
      

      {1}

      {2}

      {3}

      ", new object[] { imageAttach.ContentId, GetString(Resource.String.EmailExportSettings_MessageBodyLine1), GetString(Resource.String.EmailExportSettings_MessageBodyLine2), GetString(Resource.String.EmailExportSettings_MessageBodyLin

      N Offline
      N Offline
      Nelek
      wrote on last edited by
      #2

      It is really nice that you wrote the message giving Thanks to the people here in CP. Pity is I had to kill it, due to the link. It would be considered site driving and it is not allowed. Please write the message again without the link and it will get through.

      M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

      2 1 Reply Last reply
      0
      • N Nelek

        It is really nice that you wrote the message giving Thanks to the people here in CP. Pity is I had to kill it, due to the link. It would be considered site driving and it is not allowed. Please write the message again without the link and it will get through.

        M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

        2 Offline
        2 Offline
        24 7docs
        wrote on last edited by
        #3

        Buy drivers license, ID(whatsap:: +27838808170)ielts passports TOEFL, Visa

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups