Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run single java file with standard main(String [] args) method - Android Studio

To start with - Yes, I know that this is crazy/strange. But I need it :).

I want to find simpliest way to run single java file (and prefer non-terminal answers :) - if they are possible ) in Android Studio. I mean random .java file from my Android project in which I'll write main(..) method. And there's one more thing: I don't want to create any new modules (I've already seen answers about adding Java library module). I just want to click something and run my (single) file, the same way as I can do it in Eclipse. Is it possible?

like image 769
Mkr Avatar asked Nov 25 '14 21:11

Mkr


People also ask

How to Run main class in Android Studio?

Android Studio will automatically give an option "Run YourClass. mainActivity()", when you right-click anywhere in the editor's editing space. Just right click in the Java file and there will be an option to run that particular Java class.

What is the equivalent of main () method in Android system?

Actually, the main() method is the Android framework class android. app. ActivityThread . This method creates the Main (UI) Thread for an OS process, sets up the Looper on it and starts the event loop.


1 Answers

One thing that might be confusing you, like it was confusing me:

If there is the standard method to start Java application

public static void main (String[] args ) {
// your block here

}

Android Studio will automatically give an option "Run YourClass.mainActivity()", when you right-click anywhere in the editor's editing space.

Just right click in the Java file and there will be an option to run that particular Java class.

like image 143
erluxman Avatar answered Sep 22 '22 12:09

erluxman