---
title: 안드로이드 앱 사용자 등록 및 로그인 구현 튜토리얼
slug: docs-kr/android/working-with-users/login-android-tutorial
description: Back4App과 Parse Server를 활용한 안드로이드 사용자 등록, 로그인 및 로그아웃 구현 방법 안내.
image: https://www.back4app.com/images/logo-social.png
createdAt: 2024-03-14T10:52:14.074Z
---

# 로그인 및 사용자 등록 튜토리얼

## 소개

이 섹션에서는 Back4App을 사용하여 간단한 사용자 등록으로 앱을 만드는 방법을 살펴보겠습니다.[Parse Server 핵심 기능](https://www.back4app.com/product/parse-server)

이 튜토리얼은 <font color="#2166ae">`buildToolsVersion=30.0.2`</font>로 Android Studio 4.1.1에서 생성된 기본 앱을 사용합니다. <font color="#2166ae">`Compile SDK Version = 30.0.2`</font> 및 <font color="#2166ae">`targetSdkVersion 30`</font>

:::hint{type="success"}
언제든지 이 튜토리얼로 구축된 전체 Android 프로젝트에 대한 액세스를 GitHub 리포지토리에서 확인할 수 있습니다.

- [Kotlin 예제 리포지토리](https://github.com/templates-back4app/Android-Parse-Sdk-Kotlin)
- [Java 예제 리포지토리](https://github.com/templates-back4app/Android-Parse-Sdk-Java)
:::

## 목표

Parse를 사용하여 로그인하고 등록하는 방법을 배울 것입니다.

우리가 달성할 목표의 미리보기입니다 :

::Image[]{src="https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/aN4ASiBVNZ8ziFhqTP4Mb_user-registrationv2.gif" size="50" width="346" height="750" position="center" showCaption="false"}

## 전제 조건

:::hint{type="info"}
**이 튜토리얼을 완료하기 위해 우리는 다음이 필요합니다:**

- [안드로이드 스튜디오](https://developer.android.com/studio/index.html)
- Back4App에서 생성된 앱.
  - **참고:&#x20;**&#x20;[새 파스 앱 튜토리얼](https://www.back4app.com/docs/get-started/new-parse-app)을 따라 Back4App에서 Parse 앱을 만드는 방법을 배우세요.
- Back4App에 연결된 안드로이드 앱.
  - **참고:&#x20;**&#x20;[Parse SDK 설치 튜토리얼](https://www.back4app.com/docs/android/parse-android-sdk)을 따라 Back4App에 연결된 안드로이드 스튜디오 프로젝트를 만드세요.
- 안드로이드 4.1 (젤리빈) 이상에서 실행되는 장치 (또는[ 가상 장치](https://developer.android.com/studio/run/managing-avds.html))
:::

## 1 - 라이브러리 가져오기

이 단계에서는 프로젝트에서 사용할 라이브러리를 가져옵니다:

1. 우리는 다음 Parse 클래스를 우리의 활동에 추가할 것입니다.

:::BlockQuote
1    import com.parse.Pars&#x65;**;**
2    import com.parse.ParseExceptio&#x6E;**;**
3    import com.parse.ParseUse&#x72;**;**
:::

&#x20;    2\. 우리는 프로젝트에서 람다 함수를 자주 사용할 것이므로 build.gradle(Module\:App)을 통해 Java 1.8을 추가해야 합니다.

:::BlockQuote
1    compileOptions **\{**
2        sourceCompatibility **JavaVersion.**&#x56;ERSION\_1\_8
3        targetCompatibility **JavaVersion.**&#x56;ERSION\_1\_8
4    **}**
:::

## 2 - 회원가입

회원가입은 기본적으로 User 클래스에 새로운 Parse.User 객체를 생성하며, 앱에서는 “User”로 표시됩니다. <font color="#2166ae">`대시보드`</font>. 새로운 사용자를 생성할 때는 최소한 두 가지 속성을 설정해야 합니다 => <font color="#2166ae">`ParseUser.setUsername()`</font> 및 <font color="#2166ae">`ParseUser.setPassword()`</font>.

안드로이드에서 새로운 사용자를 저장하는 데 사용되는 메서드는 <font color="#2166ae">`ParseUser.signUpInBackground()`</font>, 이는 콜백 함수와 함께 제공될 수 있습니다.

:::hint{type="info"}
**참고**: 이 특별한 클래스의 객체는 <font color="#2166ae">`대시보드`</font>에 <font color="#2166ae">`ParseObject.save()`</font> 메서드로 저장되지 않습니다.
:::

작동하게 하려면 <font color="#2166ae">`SignUpActivity`</font> 다음 단계를 따르세요:

1. 가져오기&#x20;

:::BlockQuote
1   import com.parse.SignUpCallbac&#x6B;**;**
:::

당신의 <font color="#2166ae">`SignUpActivity`</font>, **1단계**에서 가져온 종속성과 함께.

&#x20;    2\. 사용자 등록을 구현하려면, 다음 코드를 사용하세요.<font color="#2166ae">`onCreate()`</font> 메서드에서:

:::CodeblockTabs
```java
1   ParseUser user = new ParseUser();
2        // Set the user's username and password, which can be obtained by a forms
3        user.setUsername( "<Your username here>");
4        user.setPassword( "<Your password here>");
5        user.signUpInBackground(new SignUpCallback() {
6            @Override
7            public void done(ParseException e) {
8                if (e == null) {
9                    showAlert("Successful Sign Up!", "Welcome" + "<Your username here>" +"!");
10               } else {
11                   ParseUser.logOut();
12                   Toast.makeText(SignUpActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
13               }
14           }
15       });
```

```kotlin
1   val user = ParseUser();
2        // Set the user's username and password, which can be obtained by a forms
3        user.setUsername("<Your username here>");
4        user.setPassword("<Your password here>");
5        user.signUpInBackground(SignUpCallback() {
6            if (it == null) {
7                showAlert("Successful Sign Up!", "Welcome" + "<Your username here>" + "!");
8            } else {
9                ParseUser.logOut();
10               Toast.makeText(this, it.message, Toast.LENGTH_LONG).show();
11           }
12       });
```
:::

:::hint{type="info"}
예제 프로젝트에서 이 코드는 <font color="#2166ae">`회원가입`</font> 버튼 콜백 안에 배치됩니다.
또한, 사용자 이름과 비밀번호는 **텍스트 편집**을 사용하여 가져옵니다.
:::

&#x20;    3\. 경고 대화 상자를 표시하는 추가 메서드를 추가하면 프로세스가 더 전문적으로 보이는 것이 흥미롭습니다. 아래 메서드는 이를 수행합니다:

:::CodeblockTabs
```java
1   private void showAlert(String title,String message){
2        AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this)
3                .setTitle(title)
4                .setMessage(message)
5                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
6                    @Override
7                    public void onClick(DialogInterface dialog, int which) {
8                        dialog.cancel();
9                        // don't forget to change the line below with the names of your Activities
10                       Intent intent = new Intent(SignUpActivity.this, LogoutActivity.class);
11                       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
12                       startActivity(intent);
13                   }
14               });
15       AlertDialog ok = builder.create();
16       ok.show();
17   }
```

```kotlin
1   private fun showAlert(title: String, message: String) {
2        val builder = AlertDialog.Builder(this)
3                .setTitle(title)
4                .setMessage(message)
5                .setPositiveButton("OK") { dialog, which ->
6                    dialog.cancel()
7                    // don't forget to change the line below with the names of your Activities
8                    val intent = Intent(this, LogoutActivity::class.java)
9                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
10                   startActivity(intent)
11               }
12       val ok = builder.create()
13       ok.show()
14   }
```
:::

## 3 - 로그인

로그인은 세션 객체를 생성하며, 이는 로그인한 사용자를 가리킵니다. 로그인에 성공하면, <font color="#2166ae">`ParseUser.getCurrentUser()`</font>는 사용자 객체와 <font color="#2166ae">`대시보드`</font>에서 생성된 세션 객체를 반환합니다. 그렇지 않으면, 대상 사용자 이름이 존재하지 않거나 비밀번호가 잘못된 경우 null을 반환합니다.

로그인 작업을 수행하는 데 사용되는 메서드는 <font color="#2166ae">`ParseUser.logInInBackground()`</font>, 이는 사용자 이름과 비밀번호 문자열만큼 많은 인수를 요구하며, 콜백 함수를 호출할 수 있습니다.

:::hint{type="info"}
**참고:** 회원가입 후 자동으로 로그인이 수행됩니다.
:::

To make <font color="#2166ae">`LoginActivity`</font> work, follow these steps:

1. Import into your<font color="#2166ae">`LoginActivity`</font>, in addition to the dependencies imported in the **Step 1:**

:::BlockQuote
1    import com.parse.LogInCallbac&#x6B;**;**
:::

&#x20;     2\. To implement user login function, simply use the code:

:::CodeblockTabs
```java
1   private void login(String username, String password) {
2        progressDialog.show();
3        ParseUser.logInInBackground(username, password, (parseUser, e) -> {
4            progressDialog.dismiss();
5            if (parseUser != null) {
6                showAlert("Successful Login", "Welcome back " + username + " !");
7            } else {
8                ParseUser.logOut();
9                Toast.makeText(LoginActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
10           }
11       });
12   }
```

```kotlin
1   fun login(username: String, password: String) {
2        progressDialog?.show()
3        ParseUser.logInInBackground(username,password) { parseUser: ParseUser?, parseException: ParseException? ->
4            progressDialog?.dismiss()
5            if (parseUser != null) {
6                showAlert("Successful Login", "Welcome back " + username + " !")
7            } else {
8                ParseUser.logOut()
9                if (parseException != null) {
10                   Toast.makeText(this, parseException.message, Toast.LENGTH_LONG).show()
11               }
12           }
13       }
14   }
```
:::

:::hint{type="info"}
In the example project, this code is placed inside a <font color="#2166ae">`LOG IN`</font> button callback.
Also, username and password are caught using **Edit Texts**.
:::

:::hint{type="info"}
The method <font color="#2166ae">`showAlert`</font> is the same that you added in the <font color="#2166ae">`SignUpActivity`</font>, don’t forget to change its <font color="#2166ae">`Intent`</font> arguments though.
:::

## 4 - 로그 아웃

로그 아웃은 로그인한 사용자의 활성 세션 객체를 삭제합니다. 로그 아웃을 수행하는 데 사용되는 방법은 <font color="#2166ae">`ParseUser.logOutInBackground()`</font>입니다.

사용자 로그 아웃을 구현하려면 아래 코드를 사용하면 됩니다. <font color="#2166ae">`LogoutActivity`</font>:

:::CodeblockTabs
```java
1       ParseUser.logOutInBackground(e -> {
2               progressDialog.dismiss();
3               if (e == null)
4                   showAlert("So, you're going...", "Ok...Bye-bye then");
5       });
```

```kotlin
1   fun login(username: String, password: String) {
2        progressDialog?.show()
3        ParseUser.logInInBackground(username,password) { parseUser: ParseUser?, parseException: ParseException? ->
4            progressDialog?.dismiss()
5            if (parseUser != null) {
6                showAlert("Successful Login", "Welcome back " + username + " !")
7            } else {
8                ParseUser.logOut()
9                if (parseException != null) {
10                   Toast.makeText(this, parseException.message, Toast.LENGTH_LONG).show()
11               }
12           }
13       }
14   }
```
:::

:::hint{type="info"}
예제 프로젝트에서 이 코드는 <font color="#2166ae">`로그 아웃`</font> 버튼 콜백 안에 배치됩니다.
:::

:::hint{type="info"}
메서드 <font color="#2166ae">`showAlert`</font>는 <font color="#2166ae">`loginActivity`</font>와<font color="#2166ae">`SignUpActivity`</font>에 추가한 것과 동일합니다. 그러나 <font color="#2166ae">`Intent`</font> 인수는 변경하는 것을 잊지 마세요.
:::

## 5 - 앱 테스트하기

1. 앱을 실행하고 몇 명의 사용자를 생성한 후, 등록한 후 다시 로그인해 보세요.
2. 다음에서 로그인하세요 [Back4App 웹사이트](https://www.back4app.com/).
3. 앱을 찾아서 <font color="#2166ae">`대시보드`</font>><font color="#2166ae">`코어`</font>><font color="#2166ae">`브라우저`</font>><font color="#2166ae">`사용자`</font>.

이 시점에서 아래와 같이 사용자를 볼 수 있어야 합니다:

![](https://api.archbee.com/api/optimize/yD3zCY-NNBBIfd0uqcfR5/A9nIfbXRgRJQrRuLJDOzG_image.png)

:::hint{type="info"}
**참고**: 위에 표시된 코드를 사용하여 사용자가 로그인할 때마다 <font color="#2166ae">`세션`</font>이 <font color="#2166ae">`대시보드`</font>에서 열립니다. 그러나 사용자가 로그아웃하면 해당 <font color="#2166ae">`세션`</font>이 종료됩니다. 또한, 로그인 또는 가입 시도가 실패할 때마다 Parse Server <font color="#2166ae">`대시보드`</font>에서 열린 <font color="#2166ae">`세션`</font>이 삭제됩니다.
:::

## 완료되었습니다!

축하합니다! 이제 Back4App을 통해 Parse Server의 핵심 기능을 사용하여 앱에 로그인하고, 등록하고, 로그아웃할 수 있습니다!
