executing code every 24h, but only if app is opened - java

I want to execute specific code in my app every 24h.
I know how to use AlarmManager but problem is I don't want that code to be executed if app isn't running.
I want it to be executed when app starts but only if 24h has passed after last execution.
It doesn't matter if more 24h has passed
For example if user opens my app for the first time code will execute. If it opens it again after 20min nothing will happen. if it opens it after 24h or more code will be executed.

I would save to a file, the time the program was started. You can check this before writing to see how long it has been.
Note: if there is a task you want to run at least 24h apart, you really want the last time the task was performed. e.g. if the application is opened every 8h you still want it to run.

Why don't you use Shared Preferences storage option provided by Android platform to store last access information and then act accordingly.
For more details refer this link: Android developer reference for Storage Options

Related

Reflecting code inside of Android applications from hosting servers without new build

Greetings of the day
I know you have a busy schedule. Would you like to give me your 10 to 20 minutes for a discussion. I have a doubt and did some google search for this. There are some information but those are not much clear.
I am sure that if this doubt resolved and we found the solution to achieve the objective. It will help us for each and every project. It can be a time taking solution but only required once to get the line.
Doubt :- Do we can make an application which hit an url and take a response and according response performe some commands to write and read or modify the file itself.
In Java or other language.
In short without building new generated file code can reflect as like in web it happen.
Example :- we write and save the code file in web development at host location. Browser hit the url and show the output as it is newly writen code.
If we have added a new button in our website it reflects after saving the file.
Same thing I wanted to perform in Java and Android or dart.
Issue to solve:- the review time taken by play store. And for each update we need to build new apk each time.

How we can test selenium codes without doing login again

I'm trying to make a simple code automation. It firstly, needs to login, then perform some action.
When I run the code in eclipse it logs in (i'm solving captcha manually for 3 minutes) then the process should start.
After some changes when I click run, it tries to login again. This happens every time.
But after different attempts to fix it, the login process still takes a long time for me. After x amount of attempts it also causes me to be banned from the site.
So, without login again and again. After every code changes, how can I get my automation to work?
E.g: RUN
1-)go to youtube.com
2-)login
3-)go to any song
4-)get song's name, save
I'm making some code changes on 3rd and 4th process, and then i'm clicking RUN. It's starting at 1st step again (login). After clicking run 3-4 times, It causes me to be banned from the site.
The main question: How can i try 3rd 4th step codes without login
process again.
I hope you can understand my issue.

One-time Java Configuration file on a desktop app

I am doing now a desktop app like a organizer. When the program starts, it has 0 tasks, obviously. I go adding more tasks, but when I close the program and then restart it, all the tasks I have done will be on null.
I think I can use a file that the program will consult. This file will have all the relevant information for load all the tasks.
But, and problem comes here, I want to make a question like "Where do you want to save the configuration file?" It is like Eclipse`s message at start with the workspace. The idea is that the message will only be show until the user specify a valid route.
Can we do this in Java?
Use java.util.prefs.Preferences: https://docs.oracle.com/javase/8/docs/api/java/util/prefs/package-summary.html

Java Application (With GUI) as a service

We have a a Java app that takes a few registers off a database and sends them back and forth to a web service, nothing too complicated. This java app has a GUI that informs the user about what's going on with the operations it performs, as well as providing means for configuring certain aspects of its execution and giving the user the opportunity to deal with errors that may happen.
The thing is, this application needs to run all the time, even if the user isn't logged on. I tried setting a windows task to make it run when the computer starts, but if that happens the program runs on the background and the interface never comes up.
We could break the interface away from the main project and make them run separately, so the service runs on the background quietly and the user is free to open and close the interface to their heart's content, but unfortunately we suffer from coupling problems in our project which makes that road a little more arduous than it should be.
So the question is: Is there a way to set a service up so that it runs even when the user isn't logged in, but once he does, the interface also comes up?
Our only target platform is, for now, Windows.
to your question : "Is there a way to set a service up so that it runs even when the user isn't logged in, but once he does, the interface also comes up?" the response is Yes and called JavaExe.
look its examples in JavaExe.zip, in particular example8 or 23
Only separation of UI is an answer here. Downgrading to XP doesn't make sense. You can also simply build that as a webapp and try to leverage esbeetle.com for interfaceing and doing all the logic.

Java: (Threads/Timer) Run a function everyday at say 6AM

I have my application on Windows platform and want a java function to be executed everyday at some particular period of time. Need some guidance how to go about it. Have already looked for some previous posts but need some understanding of which method to use and how?
Thanks.
If you're on Windows, use scheduled task
If you're on Linux/Unix, use cron
You may find Quartz of use. It's a Java framework which provides the ability to invoke tasks at particular intervals, at particular times of day etc.
So you can invoke Tomcat and the Quartz framework - built into your app and suitably configured - can invoke methods at particular intervals/times of day.
I made the same process in C#.
-First Create table that includes time table that when you want to run your function
- Get time from table and calculate interval like after checking adding +1 day or 24 hours to your time which you get from table.
I made it for schedule in university.I used dayname,date,time.Like this you can control also which day ,which time will run your function
Since you are using JSP and having your own server, you might set it as a scheduled task (Windows) to run at 6AM Everyday
First this is called Cron Jobs
Go to the Task Scheduler
Win 7:
Start -> All Programs -> Accessories -> System Tools -> Task Scheduler
From the right panel choose "Create Basic Task ..."
Give the task a name, hit next.
In the trigger tab, choose daily, then click next.
The next tab will let you set the specified date to start launching the trigger, the time, set the time and hit next.
In the Action tab, choose "Start A Program", then Next/.
In the next tab, click browse next to the program/script field, then navigate to the location of the Apache tomcat Server and choose the application.
(for the appache from WAMP Package: wamp\bin\apache\Apache2.2.11\bin\httpd.exe) tom cat will difer a bit I guess.
hit Next then Check the "Open the Properties Dialog for this task when I click Finish" then click Finish.
Now go to the action tab, select the first and only action available, click edit.
in the program/script field and modify type a space, then URL
change the URL to the URL you use to access your page.
This will let you be able to launch the script everyday at 6AM.

Categories