How to create service project without any activity? - android

Just starting with android.
I try to create project that will send notification ( some bit for example ) to my FTP server every 3 hours.
I don't know how to create this project because each time i create new android project i must have only project with activity - and i don't need any activity - just need a service that will run when i install it on the device.

each time i create new android project i must have only project with activity
If you are using Eclipse, uncheck the "Create activity" checkbox that tells the new project wizard to create an activity.
If you are using android create project, yes, it will create an activity for you. You can delete the Java class and the manifest <activity> entry if you want.
In reality, you will wind up leaving all of it alone.
just need a service that will run when i install it on the device.
First, a service does not run just because you install it on the device. It only runs if you write code to cause it to run.
Second, while you might think "well, I will just get control at boot time and start the service then", that is possible, but it will not work on Android 3.1+ devices unless the user has run an activity first. This is to prevent "drive-by" malware.
So, I suggest that you leave the activity in there, if you want your app to work.
Moreover, unless this app is only for yourself, your users need the activity, to:
Control the behavior of the service, such as changing the "every 3 hours" setting to something they prefer
Read your license agreement
Read your documentation, including how to get support
Etc.

Related

Android application process

I have some very basic questions, Great to get answer.
Q 1. Whenever anyone creates android application which generates *.apk file and installed this apk on device, can we surely say that android has created new process for this apk ?
Q 2. If Android app manifest file has tag for application and inside it has service only. and If it installed on device as apk.
Now this service remotely going to be access by another android application using aidl which has application tag and inside that there is Activity. which access above remote service.
can we say that service accessing App and remote service both are different process ? I think Yes.
My assumption
Any app which has tag inside manifest file and which generates apk and get installed on android device then on launch by any other App remotely or starts its own on some event intent then android framework will launch new process to start for this apk. Please correct ?
android:process can be set if any components of same application want to run in another process or different applications component want to run in the same process.
Please read carefully and then only reply, let me know if need more explanation.
R1. The apk is just a package. When you start your application, low level, the linux machine on which Android is based will fork a process called Zygote. Then the copy of the Zygote (that already has either an instance of the Dalvik Machine mapped in its address space, or the ART libraries and Ahead Of Time compiled application code), will load all application specific java classes, and all core dependencies (native libraries), plus all application specific native code.
So it does create a new process only when you start the application.And hypothetically, you could create any number of processes for the same apk, which is just a container.
R2. If in the AndroidManifest you have a service declared as "exported", it will run in a separate process. Your application will then communicate with this process using an IPC mechanism called Binder, which is a specific implementation of shared memory at kernel level. AIDL is a meta-language interpreted at build time and used to auto-generate Java stubs that will work deep down with native binder code.
Whenever anyone creates android application which generates *.apk file and installed this apk on device, can we surely say that android has created new process for this apk ?
No. Installing an app does not fork a process for that app.
can we say that service accessing App and remote service both are different process ? I think Yes.
By default, they will be in separate processes.

com.android.server.PackageManagerServices and Android

I am trying to debug native code in my Android App development and I need to have com.android.server.PackageManagerServices in the device. I search the info for PackageManagerServices and can't find good info in the web.
My queries are
(1)Where to get com.android.server.PackageManagerServices?
(2)How to create this service available on the device?
Thanks
PackageManagerService is located at /frameworks/base/services/java/com/android/server/pm/
PackageManagerService is a system service which gets started by SystemServer.java at boot time and always keeps running. one need not to create another instance of it.
You can refer aosp source code at http://androidxref.com

A single BroadcastReceiver in an Android APK file.

Suppose we have an Android APK file which contains only a single BroadcastReceiver.
Will this form of the APK file be installed on Android devices be installed successfully and can the BR receive intended intents? I thought it will, but my experiment showed it does not. I am not sure why, but the installation of such APK files (with a single BR) seems to fail all the time.
A solution to this problem is to add a dummy Activity to the package. Then the installation succeeds, and the BroadcastReceiver can receive all intended intents!
Please share your opinion on this matter.
I always thanks you all for helps!
Will this form of the APK file be installed on Android devices be installed successfully and can the BR receive intended intents?
No.
I am not sure why, but the installation of such APK files (with a single BR) seems to fail all the time.
No, but the BroadcastReceiver will not receive broadcasts until something has directly invoked one of your components via an explicit Intent (i.e., an Intent that identifies the class). Normally, that will happen by the user launching your LAUNCHER activity. This has been the case since Android 3.1, about three years ago (see "Launch controls on stopped applications" in the Android 3.1 release notes).
You need at least one Activity for landing page in the android app. What are you expecting will happen when the app is launched manually?

Referencing another package activity within a tab host

I've created an app that has been in the android marketplace for a few months now. I'm trying to create a complimentary app that will be used inside the first app. I need the second app to be optional, and not necessary for the first app to work properly. I'm hoping to call the main activity from the second app within a Tab Host tab on the first app.
My questions are: how do I run an activity from a secondary app with a different package? Is it possible to have the activity be in a tab host?
I'd be happy to post code, but my code seems to be nowhere close to what I'm trying to get. I don't think I can adjust the build path of the primary app, because the secondary app can't be required. Also, Since the app has been in the marketplace for a while, I can't use SharedUserIds.
Thanks for all help.
TJ
It is not possible to do it to run any arbitrary activity in your app.
I have done this before, with activity group, which has been already deprecated. And there are also limitations to use this approach:
Your app has the same UID with the target package.
Your app has system UID
If you met either condition list above, you can start the child activity and get its window root view, and add into your layout.

What is android.permission.SET_PROCESS_LIMIT used for in an android application?

I have been trying to figure this out on the web with no information whatsoever as to what this actually does. The Google Manifest information says:
Allows an application to set the maximum number of (not needed) application processes that can be running.
I am thinking this is not a third party app permission but I need to be sure, its for our embedded device.
My guess is that this limits the number of processes that one application can have open when calling android:process=".RemoteActivity" in the manifest.
Anyone? Thank you.
It's a development/debug intended permisson. And just do what it says. Remember that when you run an app, android creates a process for all it's activities. This is, if you start opening the different activities of your application, you use the same process. However, Android let's you choose if an activity uses the main process or another new one. That's why this permission exists.
Sources:
http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html
http://developer.android.com/reference/android/Manifest.permission.html#SET_PROCESS_LIMIT

Categories

Resources