Related
An Activity that started a service finished. That means the process the Activity run in has finished. So all of threads the process created would stop. But why the thread serving the Service that the Activity started through startService() method is alive?
I'm not sure what you're asking. A service will continue to run until it ends itself, even if the activity that launched it ends.
Gene Poole said:
I'm not sure what you're asking. A service will continue to run until it ends itself, even if the activity that launched it ends.
Click to expand...
Click to collapse
I'am sorry, if I'am extremely obvious. SDK says a service is not a process and is not a thread, but it runs in the same process as the application it is part of. What is it? Why can it keep running after the process finished? I'am a little confused.
"Process" with respect to the JVM is just an execution context within the virtual machine. In the typical case as I understand it, an app, activity, service, etc. can exist in the process space and can interact with each other, but not necessarily depend on each other.
jiyeyuran said:
An Activity that started a service finished. That means the process the Activity run in has finished.
Click to expand...
Click to collapse
No. You are confused and you think "Activity" = "Application".
jiyeyuran said:
I'am sorry, if I'am extremely obvious. SDK says a service is not a process and is not a thread, but it runs in the same process as the application it is part of. What is it? Why can it keep running after the process finished? I'am a little confused.
Click to expand...
Click to collapse
It cannot continue after the process finished.
This simply means: the process has not finished! :facepalm:
Read here.
Application = Activities + Services + Receivers + Providers.
When the first one is called, the Application process is created.
When the last one has finished, the Application process is no longer.
So if you start an Activity, a process is created.
Then you call a Service from the Activity, it gets added to the same process (unless you specify a different process, check the docs link I gave you).
When your Activity finishes and the Service is still alive, the process will live on.
Thank you very much. Your explain is very clear. Without specially indicating, a service from the Activity and the Activity will run in the same thread. But if startService and bindService work at the same service, you need to very take careful of using them. For example, if you start a service with startService call and bind the service twice, then you unbind the service, an exception will be waiting for you.
I have spent my weekend in finding out the service mechanism. Hope you can understand my poor English.
jiyeyuran said:
Thank you very much. Your explain is very clear. Without specially indicating, a service from the Activity and the Activity will run in the same thread. But if startService and bindService work at the same service, you need to very take careful of using them. For example, if you start a service with startService call and bind the service twice, then you unbind the service, an exception will be waiting for you.
I have spent my weekend in finding out the service mechanism. Hope you can understand my poor English.
Click to expand...
Click to collapse
I don't understand if you are asking a question or not.
Read the link I gave you, it has a brief and simple description to understand when you need to use an Activity or a Service (or a Broadcast Receiver or Content Provider, yeah).
What are you trying to accomplish, anyway?
Our teacher ask us to develop a SmartHome Manage software on the android platform. The application can turn on and turn off some appliances in home like frigo, tv, window, etc. It can also receive the telephone messages, so we may need to download voice files from the service runing at a computer. Obviously, android service is a good choice to spawn a thread for downloading voice files. As cutomers can take other service operations during the period of downloading voice file, the service may be binded many times before it is unbinded. I wonder if it will cause problems when a service is binded repeatedly before unbinded? Which aspects we need to take care of when we use android service?
Android SDK says when binding a servcie, onCreate() (if service don't start) and onBind() will execute. When you bind again, the onRebind() will excute if the return value of onUnbind() is true. But the problem is that when I bind secondly, the first unbind haven't returned yet. As a result, the onRebind() method cann't be executed. Does it cause problems?
Major Changes to the UI and usage Check the market for the latest version or use the version attached to this post. If you have trouble with the posted version use the market version as it will always have the lastest fixes. The attached version might have an issue I did update the attached version but I won't manage it here.
1. Complete task ui revamp, easier building and management of tasks.
2. Added cron string builder, you can now build time string with rolling pickers and show you the next execution date (great for visualizing your time string). This will build 98% of the schedules most of us use.
3. Clicking on the clock in the Cron tab will now show all the active queued tasks (tasks that were active when cron was started).
4. Added option to run on boot for a task, this makes tasks execute if the option is checked and cron is set to auto restart. This allows a task to run only, at boot, and the task does not have to be active. (Sascha Kerkeling).
5. Added option to import scripts, you can now import the contents of a script file (Sascha Kerkeling).
6. You can now activate/deactivate a task from the tasks view.
7. I have kept the old tasks view in place for this update so that you can trasnfer any existing tasks over... it will be removed next update.
8. Added cron change log... this will automatically show once every update.
9. Added safe guard so that a reboot command cannot be fired with the execute on boot option (just in case).
10. Added better logging of why task commands fail, this will show as a complete stack trace in the execution log.
11. Added 6 new default tasks that might be helpful (Sascha Kerkeling, A. Simmons).
This is cron for your phone a small app I developed to allow me to restart/shutdown my phone on a schedule, but Cron has a billion uses and I wanted to see how others will use it I also use it to backup my market apps on a schedule.
**WARNING YOUR PHONE NEEDS TO BE ROOTED TO USES THIS APP**
This app can be dangerous if used wrong, if you use this app incorrectly and mess your phone up its your fault not mine. You wouldn't blame snap-on if the wrench you used breaks a bolt on your car, so don't try and blame me for what you do wrong with this tool. If you do I will only point at you and laugh.
**WARNING YOUR PHONE NEEDS TO BE ROOTED TO USES THIS APP**
Features:
Uses the standard Cron4Phone time string schedule.
Run all type of shell commands on any schedule you can think of.
Run tasks to shut your phone off on a schedule.
Auto restart so Cron4Phone continues to run even after a restart.
Small apk foot print.
unlimited concurrent tasks available.
Set a task as inactive/active.
Test execution setting to log commands only.
I'm really looking forward to seeing how others will use this tool. Please feel free to point out errors or suggestions. If you want help setting schedule I can give pointers.
Android market download
ooooh
as soon as I can liberate a copy from a market enabled phone I will begin tinkering... that might take a while
would you consider releasing it to f-droid.org if your license allows?
Here you go
Here's a copy... I haven't opened the source up although I probably will in the future, when I have more time to spend on it (working on a video game). This copy is signed with the same key as the market version and its ad supported I will slowing be updating the task management part of the ui.
this is the market description
*****YOUR PHONE NEEDS TO BE ROOTED TO USES THIS APP*****
This app can be dangerous if used wrong, if you use this app incorrectly and mess your phone up its your fault not mine. You wouldn't blame snap-on if the wrench you used breaks a bolt on your car, so don't try and blame me for what you do wrong with this tool. If you do I will only point at you and laugh.
*****YOUR PHONE NEEDS TO BE ROOTED TO USES THIS APP*****
-----------NEW INFO READ------------
After another full audit and help from Sascha Kerkeling and M. Porter, I redesigned Cron to no longer use long running service and instead now (correctly) uses AlarmManager to precisely execute tasks in a WakefullIntentService. This will will insure that all task are executed even when the phone is in deep sleep (even when the phoen doesn't hold any other wake locks) and barely uses any resources to accomplish this. I will now be able to focus on the UI... Dynamic task here we come!
-----------NEW INFO READ------------
Cron4Phone is a time-based job scheduler in Unix-like computer operating systems. Cron4Phone enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. It is commonly used to automate system maintenance or administration, though its general-purpose nature means that it can be used for other purposes, such as connecting to the restart your phone and backing up apps. This is a foreground service so that it is guaranteed to stay running, use the home key to back out of the app or double tap the back arrow to kill the app. Killing the app kills the service.
Features:
Uses the standard Cron4Phone time string schedule.
Run all type of shell commands on any schedule you can think of.
Run tasks to shut your phone off on a schedule.
Auto restart so Cron4Phone continues to run even after a restart.
Small apk foot print.
5 concurrent tasks available.
Set a task as inactive/active.
Test execution setting to log commands only.
This tool can be used to do endless amount of things, I'm really looking forward to see what you guys can use it for so please share your ideas, command and schedules.
I have provided 3 tasks that I thought would be the most useful to most users shutdown, restart, and backup apps.
Interesting
Sent from my SCH-I500 using XDA App
testing your application, it's really simple.., i'm hoping custom task can be added more
New version
EDIT: removed refer to the OP...
I attaching a new version to this post, it fixes a bug with the restart on reboot not registering your tasks. Basically if your phone reboots and you have active tasks and cron is started it will keep on running.
As for the ui I will slowly work on updating the task tab so that task can be managed dynamically, other than that the rest of the ui will basically stay the same, I want it to stay simple and small.
The market version has also been updated.
ttt for updates!
Very nice app, I would like to see more Linux tools working with Android.
Sent from my Zio using xda premium
Yes and this was one that I thought was needed, and while you can run cron on your phone through busy box, this app doesn't need that module and uses standard java to mimic cron all while putting a clean ui on top of it.
Thank you.
[EDIT]
ACK! Okay, I just stopped and started the cron and it is now working. Sorry about this post. :-/
[/EDIT]
I am going to resurrect this thread because I can't figure this out and I'm a Unix admin. I have tried to set a schedule for a job to run every 5 minutes (this was to test, the actual job will run every 30 minutes). I have tried to set */5 * * * *, /5 * * * *, and 0,5 * * * * and none of them work for every 5 minutes. Can you look into this or give an example in here? Thanks!
fstrim
If anyone is still out there -- I use Cron4Phone to schedule daily reboots and would like to add an fstrim command to run daily, maybe weekly. Can anyone help me with setting this up (command syntax, etc)?
Is there any chance to get the apk from somewhere? Thanks in advance!
How to let function wait AsyncTask finish then only perform return, purposely my function need to get a result processed from AsyncTask, any expert can help?
lye85 said:
How to let function wait AsyncTask finish then only perform return, purposely my function need to get a result processed from AsyncTask, any expert can help?
Click to expand...
Click to collapse
You cannot let a method running in the UI (main) Thread of your application wait for an Async task to finish, that would block the UI Thread and result in an "App is not responding" dialog. To use Async tasks and get the result, read this documentation, especially "The 4 steps". You'd have to use the onPostExecute(Result) method to get the result. You can then call the function which needs the result again. But never wait for an async task to finish, that's not the point of it!
I've just posted such a onPostExecute example here, seems this is exactly what you asked for by coincidence..
thanks for all reply, but is there any other to call ksoap without using Asynctask?
Android- Asynchronous
lye85 said:
How to let function wait AsyncTask finish then only perform return, purposely my function need to get a result processed from AsyncTask, any expert can help?
Click to expand...
Click to collapse
Here You have Many options with you like
1. Just Load Your required UI Page After the Post Execute Method
2. Just Show Dummy Text firstly then update the ui after you get your response.
3. Just take one flag which is updatinng on post execute method after that u can update your ui
First question would be - why are you using ASYNCtaks if what you require seems to be a sync task If you're using it because you want to change GUI when the task is finished, the easiest way would be of course to use onPostExecuted method of AsyncTask. The other way would be to supply a callback/runnable to your async task (but why would you do that when there's onPostExecuted is beyond my comprehension).
Note that on Android you have to think asynchronically. I've tried to wait for async tasks to finish, but believe me - it was not worth it and I was severely punished!
Hi,
I have released an app for screen recording, Screen Recorder
since am new here, am not able to post as link. play.google.com/store/apps/details?id=vee.screen.recorder
which uses the native screen recording API
I have a problem with stopping screen recording, How to interrupt the executed command, and exit.
How to find the screen recorder binaries and embed in my app, to make it avail for all users.
Note : this app will always be remain free & no ads will be added.
VenomVendor said:
I have a problem with stopping screen recording, How to interrupt the executed command, and exit.
Click to expand...
Click to collapse
What's about sending Ctrl + C to the process?
nikwen said:
What's about sending Ctrl + C to the process?
Click to expand...
Click to collapse
Am executing code programmatically within my app
stackoverflow.com/a/3055786/1008278
I have to interrupt execution programmatically.
Executing "exit" is not interrupting current execution.
VenomVendor said:
Am executing code programmatically within my app
stackoverflow.com/a/3055786/1008278
I have to interrupt execution programmatically.
Executing "exit" is not interrupting current execution.
Click to expand...
Click to collapse
The destroy() method of java.lang.Process should work. You would need to send it from a different thread though as the other one will wait for the Process to finish due to the call of Process#waitFor().
I want to observe an app's process being killed automatically (when the app's activity is stopped and other processes need the memory). I'm keeping my eye on Android Studio's Devices pane while I launch other processes, but this doesn't seem to kill my dormant activity. Is there a way to insure that this happens (and is observable)? (I know, . . . Why would I ever want to do this? It's because I'm teaching Android and I want to illustrate this concept.)