Files
J1B4-Fitbot/docs/documentation/android/appSetup.md
2024-04-25 21:29:32 +02:00

43 lines
1.4 KiB
Markdown

# Setting up a android app
## How to make your project from a empty project
### Layout
You first need to make the layout of the app. This can be done in the res folder where you can make a android recource file. When you open that file you can drag and drop elements in the layout.
### Code
Then need to make the main class. The class will probably look like this.
```java
package com.fitbot.fitbot;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set activity_main to your respective layout file
setContentView(R.layout.activity_main);
}
}
```
With setContentView you can set the layout file that you made earlier.
``` java
setContentView(R.layout.activity_main);
```
### Manifest
For the app to be able to build you need to add the activity class to the manifest file.
```xml
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
```
In this instance MainActivity is the first class that is ran.