Why there is no main() method in android? [duplicate] - java

This question already has answers here:
Where is main() in Android?
(9 answers)
Closed 4 years ago.
A Java program execution starts from main() method. Right? Since Android apps run on Java, Then why we didn't create a main() method in Android studio?

There's one, but you don't need to see it. Android takes care of threading and keeping threads organized for you, see here.
Moreover, the entry point for an activity is the onCreate() method, so all initialization is normally done in there. The first activity run by your app is normally specified in the manifest file under the launcher keyword.
See here to know more about how android runs the launcher activity.

Related

How do I run a simple text-based Java program as an app in Windows? [duplicate]

This question already has answers here:
How can I convert my Java program to an .exe file?
(16 answers)
How to make a runnable jar file?
(4 answers)
How do I create a runnable JAR in IntelliJ as I would in Eclipse
(4 answers)
Closed 1 year ago.
I'm doing an online Java course through my university. I have just finished an assignment in IntelliJ. It's a very basic text-based game that prints information to the console using System.out.println, as well as taking keyboard inputs from the user.
The game consists of several classes, an interface, an abstract class, and the main program screen shot of structure here.
Although not part of the assignment, I am curious as to what I would need to do so this "game" could be run outside of IntelliJ as a .exe (or similar) in Windows directly. For example, if a friend wanted to play on their PC without having IntelliJ installed.
This seems quite similar to the following question
Long story short: there are quite a few ways to realise that. So i think, that you need to find that out for yourself. For me the javapackager was enough and worked fine for my cases.

How we perform the background operations when app is kill in android [duplicate]

This question already has answers here:
How to execute background task when Android app is closed / set to background?
(4 answers)
Closed 2 years ago.
I need to perform background operations when my app is completely killed.I want to send data to the server in every 10 second when my app is killed. how to perform this task.
When Android kills your app process, it can do nothing at all. Android prevents apps from doing background work in order to save battery and bandwidth for the end user. Only system processes can stay running indefinitely. I suggest reading the documentation to understand how it works.
If you want to do background work in a battery-efficient way, you should use WorkManager to schedule that.

NullPointerException on setVisibility function in FrameLayout [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I have developed android project and published to a google playstore.
In this app, for tab use, at one activity, calling frameLayout.setVisibility(View.INVISIBLE) for showing other layouts.
It is working perfectly on my android devices.
But when i check crashlytics, i can see applications crashed on that function.
I tried many google searches but i did not found the solution and did not fix yet.
Please help me on this issue.
Well, without any code snippets will be hard to realise, but since is a NPE error I am guessing that your layout is not a valid one or the fragment it was in, has been changed.

Depriving your application to run multiple times [duplicate]

This question already has answers here:
How to implement a single instance Java application?
(17 answers)
Closed 7 years ago.
I created an application in java and I want it to run only once. If the application is already running, a messagebox should popup telling the user that the application is already running.
Any idea?
You can check the running programs pid names for an instance of the current program.
Or
Run the application as an instance from another class and keep the check in the other class.

Does Android Create instances of the Activity classes or how else does it work? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Having programmed for just over 6 months in Java i decided to give android a shot,but it looks like android merely uses the Java Syntax and all else differs
Example:
I can see under app/src/java/MainApplication...
that
The Activity MainApplication extends Activity and has
onCreate() methods etc , but what i don't get is how all this works, which method in the launcher activity runs first and how?
Can you draw an analogy between java Programs in Jar files ,say like how the class declared in manifest is launched and its main method runs and how android works?
I find the whole Android framework to be very different and confusing compared to the Java, Swing, AWT and event handling model of what i practiced so far, Please help!
How is onCreate() called without creating an instance of the class and calling the method on the Object, how is it called without an Object as the method is not static too?
PS:I'm taking Udacity's android course
Basically it works as follows:
Application entry points such as activities are declared in the manifest file and it is bundled with the application APK.
The activity class is instantiated by name declared in the manifest, using reflection.
The class instance is set up (e.g. Context, Configuration) and its onCreate() and other lifecycle methods are called.
For code-level details, see e.g. performLaunchActivity() in ActivityThread.

Categories

Resources