Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an application without a main activity in android studio?

I am creating a live wallpaper in android studio. I do not want any UI besides the wallpaper, so my application contains no activities.

However, when I try to deploy to a device, I get the following error and my wallpaper will not load.

Could not identify launch activity: Default Activity not found
Error while Launching activity

How can I create an application which works that does not have a main activity?

like image 405
Cameron Martin Avatar asked Jun 30 '16 15:06

Cameron Martin


People also ask

Can we create application without activity?

You don't have to have the main activity in your application, or any activities at all. Check the manifest and remove the launcher-specific intent filter from your main activity if you don't want it to show up in the application list.

Why does an Android application has no main function?

Therefore, unlike apps on most other systems, Android apps don't have a single entry point (there's no main() function). Because the system runs each app in a separate process with file permissions that restrict access to other apps, your app cannot directly activate a component from another app.

How do I change the default main activity in Android Studio?

At the top menu in your Android Studio, select Run > Edit Configurations… menu to open the Run/Debug Configurations window. Click the OK button and run your application again. This time, the default activity launched should follow the <intent-filter> set in your AndroidManifest.

What is the difference between activity and application in Android?

They are both instances of Context, but the application instance is tied to the lifecycle of the application, while the Activity instance is tied to the lifecycle of an Activity. Thus, they have access to different information about the application environment.


1 Answers

It's perfectly fine to have no activities in your application. The build succeeds, Android Studio only fails when it tries to run it, because it doesn't know what to do.

You need to modify your run configuration. Go to "Run > Edit configurations" and under "Launch options" change "Default Activity" to "Nothing":

enter image description here

like image 158
Marcin Koziński Avatar answered Nov 11 '22 03:11

Marcin Koziński