Android에서 다시 누르면 응용 프로그램을 종료하지 않는 이유는 무엇입니까?

Eggy Sudianto

내 주요 활동은 Google 로그인을 사용하는 LoginActivity이며 사용자 로그인은 MapsActivity로 연결되며 사용자가 MapsActivity에서 '뒤로'를 클릭하면 앱에서 사용자 종료를 원하지만 이제 '뒤로'를 클릭하면 앱이 MapsActvity를 다시 열었습니다. 사용자가 종료 할 수 없습니까?

LoginActivity.java

package com.emergency;


/**
 * Created by Eggy on 4/17/2016.
 */
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.OptionalPendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;

/**
 * Activity to demonstrate basic retrieval of the Google user's ID, email address, and basic
 * profile.
 */
public class LoginActivity extends AppCompatActivity implements
        GoogleApiClient.OnConnectionFailedListener,
        View.OnClickListener {

    private static final String TAG = "SignInActivity";
    private static final int RC_SIGN_IN = 9001;

    private GoogleApiClient mGoogleApiClient;
    private ProgressDialog mProgressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);


        // Button listeners
        findViewById(R.id.sign_in_button).setOnClickListener(this);

        // [START configure_signin]
        // Configure sign-in to request the user's ID, email address, and basic
        // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        // [END configure_signin]

        // [START build_client]
        // Build a GoogleApiClient with access to the Google Sign-In API and the
        // options specified by gso.
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();
        // [END build_client]

        // [START customize_button]
        // Customize sign-in button. The sign-in button can be displayed in
        // multiple sizes and color schemes. It can also be contextually
        // rendered based on the requested scopes. For example. a red button may
        // be displayed when Google+ scopes are requested, but a white button
        // may be displayed when only basic profile is requested. Try adding the
        // Scopes.PLUS_LOGIN scope to the GoogleSignInOptions to see the
        // difference.
        SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
        signInButton.setSize(SignInButton.SIZE_STANDARD);
        signInButton.setScopes(gso.getScopeArray());
        // [END customize_button]
    }

    @Override
    public void onStart() {
        super.onStart();

        OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
        if (opr.isDone()) {
            // If the user's cached credentials are valid, the OptionalPendingResult will be "done"
            // and the GoogleSignInResult will be available instantly.
            Log.d(TAG, "Got cached sign-in");
            GoogleSignInResult result = opr.get();
            handleSignInResult(result);
        } else {
            // If the user has not previously signed in on this device or the sign-in has expired,
            // this asynchronous branch will attempt to sign in the user silently.  Cross-device
            // single sign-on will occur in this branch.
            showProgressDialog();
            opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
                @Override
                public void onResult(GoogleSignInResult googleSignInResult) {
                    hideProgressDialog();
                    handleSignInResult(googleSignInResult);
                }
            });
        }
    }

    // [START onActivityResult]
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            handleSignInResult(result);
        }
    }
    // [END onActivityResult]

    // [START handleSignInResult]
    private void handleSignInResult(GoogleSignInResult result) {
        Log.d(TAG, "handleSignInResult:" + result.isSuccess());
        if (result.isSuccess()) {
            // Signed in successfully, show authenticated UI.
            GoogleSignInAccount acct = result.getSignInAccount();
            updateUI(true);
        } else {
            // Signed out, show unauthenticated UI.
            updateUI(false);
        }
    }
    // [END handleSignInResult]

    // [START signIn]
    private void signIn() {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }
    // [END signIn]

    // [START signOut]
    private void signOut() {
        Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
                new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        // [START_EXCLUDE]
                        updateUI(false);
                        // [END_EXCLUDE]
                    }
                });
    }
    // [END signOut]

    // [START revokeAccess]
    private void revokeAccess() {
        Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
                new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        // [START_EXCLUDE]
                        updateUI(false);
                        // [END_EXCLUDE]
                    }
                });
    }
    // [END revokeAccess]

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        // An unresolvable error has occurred and Google APIs (including Sign-In) will not
        // be available.
        Log.d(TAG, "onConnectionFailed:" + connectionResult);
    }

    private void showProgressDialog() {
        if (mProgressDialog == null) {
            mProgressDialog = new ProgressDialog(this);
            mProgressDialog.setMessage(getString(R.string.loading));
            mProgressDialog.setIndeterminate(true);
        }

        mProgressDialog.show();
    }

    private void hideProgressDialog() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.hide();
        }
    }

    private void updateUI(boolean signedIn) {
        if (signedIn) {
            Intent i = new Intent(LoginActivity.this, MapsActivity.class);
            startActivity(i);
        } else {
            findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sign_in_button:
                signIn();
                break;
    }
}}

MapsActivity.java

package com.emergency;

import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.Places;
import com.google.android.gms.location.places.ui.PlacePicker;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    private GoogleMap mMap;
    int PLACE_PICKER_REQUEST = 1;
    GoogleApiClient mGoogleApiClient;
    boolean search=false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        mGoogleApiClient = new GoogleApiClient
                .Builder(this)
                .addApi(Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }

    public void onSearch(View view)
    {
        PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();

        try {
            startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
        } catch (GooglePlayServicesRepairableException e) {
            e.printStackTrace();
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }

    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */


    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.setTrafficEnabled(true);
        mMap.setMyLocationEnabled(true);
        mMap.setOnMyLocationChangeListener(onMyLocationChangeListener);

    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PLACE_PICKER_REQUEST) {
            if (resultCode == RESULT_OK) {
                Place place = PlacePicker.getPlace(data, this);
                LatLng latLng = new LatLng(place.getLatLng().latitude,place.getLatLng().longitude);
                mMap.addMarker(new MarkerOptions().position(latLng).title(place.getAddress().toString()));
                mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
                mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
            }
        }
    }

    private GoogleMap.OnMyLocationChangeListener onMyLocationChangeListener = new GoogleMap.OnMyLocationChangeListener() {
        @Override
        public void onMyLocationChange(Location location) {
            if(!search) {

                mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
                mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
                search=true;

            }
        }
    };

    @Override
    public void onConnected(Bundle bundle) {

    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {

    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.emergency"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="17" />

    <permission
        android:name="com.emergency.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.emergency.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <!-- To access accounts configured on device -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <!-- To use account credentials -->
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    //OpenGL ES version 2
    <android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <android:uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomActionBarTheme">
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name=".splashscreen"
            android:label="@string/app_name"
            android:noHistory="true"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!-- Main activity -->
        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps">
        </activity>
        <activity
            android:name=".LoginActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat"/>
    </application>

</manifest>
Bala Raja |

이 코드 시도

public void onBackPressed() {
  moveTaskToBack(true);     }

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

스크립트에서 시작된 응용 프로그램에서 Ctrl + C를 누르면 스크립트가 중단되는 이유는 무엇입니까?

분류에서Dev

응용 프로그램을 다시 시작하지 않으면 암호 변경이 반영되지 않는 이유는 무엇입니까?

분류에서Dev

PHP curl이 응용 프로그램 / json 게시에서 작동하지 않는 이유는 무엇입니까?

분류에서Dev

TCP / IP 연결을 종료 한 후 POSIX "쓰기"기능을 사용하면 응용 프로그램이 충돌합니다. 이유는 무엇입니까?

분류에서Dev

터미널에서 응답하지 않는 프로그램을 종료하는 방법은 무엇입니까?

분류에서Dev

터미널에서 응답하지 않는 프로그램을 종료하는 방법은 무엇입니까?

분류에서Dev

응용 프로그램을 열고 종료하도록 지시하는 것이 AppleScript에서 제대로 작동하지 않습니다.

분류에서Dev

프로그램이 종료되면 임시 realloc 변수를 사용하는 이유는 무엇입니까?

분류에서Dev

응용 프로그램을 다시 시작한 후 데이터가 CoreData에 저장되지 않는 이유는 무엇입니까?

분류에서Dev

설정이 완료되면 Excel 응용 프로그램을 시작하는 방법은 무엇입니까?

분류에서Dev

각도 응용 프로그램이 다른 응용 프로그램에서 각도 모듈을 지연로드하는 방법은 무엇입니까?

분류에서Dev

내 응용 프로그램에서 다른 응용 프로그램의 숨겨진 창을 표시하는 방법은 무엇입니까?

분류에서Dev

다른 응용 프로그램에서 시작된 응용 프로그램을 디버깅하는 방법은 무엇입니까? (VB6)

분류에서Dev

응용 프로그램이 C #을 종료하지 않습니다.

분류에서Dev

다른 작업 공간에서 응용 프로그램을 시작하는 방법은 무엇입니까?

분류에서Dev

내 응용 프로그램이 명령 프롬프트에서 TASKKILL에 의해 종료되는 것을 감지하는 방법은 무엇입니까?

분류에서Dev

동일한 프로그램 내에서 충돌시 Qt 응용 프로그램을 자동으로 다시 시작하는 방법은 무엇입니까?

분류에서Dev

주 활동에서 뒤로 누를 때 응용 프로그램을 종료하는 방법은 무엇입니까?

분류에서Dev

요청 된 동일한 화면에서 Windows가 응용 프로그램을 열지 않는 이유는 무엇입니까?

분류에서Dev

Win32 응용 프로그램이 한 Windows 10 컴퓨터에서는 올바르게 한국어 문자를 표시하지만 동일한 버전 및 언어 팩을 사용하는 다른 컴퓨터에는 표시되지 않는 이유는 무엇입니까?

분류에서Dev

다른 응용 프로그램의 사전 빌드 프로세스에서 cmd 응용 프로그램을 호출하는 방법은 무엇입니까?

분류에서Dev

응용 프로그램에서 게시하지 않은 Facebook 게시물을 프로그래밍 방식으로 삭제하는 방법은 무엇입니까?

분류에서Dev

백그라운드에서 BREW 응용 프로그램을 시작하는 방법은 무엇입니까?

분류에서Dev

사용자가 그래픽 응용 프로그램을 시작하기 위해 일반 sudo를 사용해서는 안되는 이유는 무엇입니까?

분류에서Dev

사용자가 그래픽 응용 프로그램을 시작하기 위해 일반 sudo를 사용해서는 안되는 이유는 무엇입니까?

분류에서Dev

Android에서 응용 프로그램을 시작할 때마다 알림 수신을 중지하는 방법은 무엇입니까?

분류에서Dev

Android에서 동적으로 버튼을 만들려고 할 때 내 응용 프로그램이 작동하지 않는 이유는 무엇입니까?

분류에서Dev

시작 응용 프로그램 기본 설정에서 응용 프로그램을 추가하는 명령은 무엇입니까?

분류에서Dev

@Transactional 롤백 봄 부팅 응용 프로그램에서 작동하지 않는 이유는 무엇입니까?

Related 관련 기사

  1. 1

    스크립트에서 시작된 응용 프로그램에서 Ctrl + C를 누르면 스크립트가 중단되는 이유는 무엇입니까?

  2. 2

    응용 프로그램을 다시 시작하지 않으면 암호 변경이 반영되지 않는 이유는 무엇입니까?

  3. 3

    PHP curl이 응용 프로그램 / json 게시에서 작동하지 않는 이유는 무엇입니까?

  4. 4

    TCP / IP 연결을 종료 한 후 POSIX "쓰기"기능을 사용하면 응용 프로그램이 충돌합니다. 이유는 무엇입니까?

  5. 5

    터미널에서 응답하지 않는 프로그램을 종료하는 방법은 무엇입니까?

  6. 6

    터미널에서 응답하지 않는 프로그램을 종료하는 방법은 무엇입니까?

  7. 7

    응용 프로그램을 열고 종료하도록 지시하는 것이 AppleScript에서 제대로 작동하지 않습니다.

  8. 8

    프로그램이 종료되면 임시 realloc 변수를 사용하는 이유는 무엇입니까?

  9. 9

    응용 프로그램을 다시 시작한 후 데이터가 CoreData에 저장되지 않는 이유는 무엇입니까?

  10. 10

    설정이 완료되면 Excel 응용 프로그램을 시작하는 방법은 무엇입니까?

  11. 11

    각도 응용 프로그램이 다른 응용 프로그램에서 각도 모듈을 지연로드하는 방법은 무엇입니까?

  12. 12

    내 응용 프로그램에서 다른 응용 프로그램의 숨겨진 창을 표시하는 방법은 무엇입니까?

  13. 13

    다른 응용 프로그램에서 시작된 응용 프로그램을 디버깅하는 방법은 무엇입니까? (VB6)

  14. 14

    응용 프로그램이 C #을 종료하지 않습니다.

  15. 15

    다른 작업 공간에서 응용 프로그램을 시작하는 방법은 무엇입니까?

  16. 16

    내 응용 프로그램이 명령 프롬프트에서 TASKKILL에 의해 종료되는 것을 감지하는 방법은 무엇입니까?

  17. 17

    동일한 프로그램 내에서 충돌시 Qt 응용 프로그램을 자동으로 다시 시작하는 방법은 무엇입니까?

  18. 18

    주 활동에서 뒤로 누를 때 응용 프로그램을 종료하는 방법은 무엇입니까?

  19. 19

    요청 된 동일한 화면에서 Windows가 응용 프로그램을 열지 않는 이유는 무엇입니까?

  20. 20

    Win32 응용 프로그램이 한 Windows 10 컴퓨터에서는 올바르게 한국어 문자를 표시하지만 동일한 버전 및 언어 팩을 사용하는 다른 컴퓨터에는 표시되지 않는 이유는 무엇입니까?

  21. 21

    다른 응용 프로그램의 사전 빌드 프로세스에서 cmd 응용 프로그램을 호출하는 방법은 무엇입니까?

  22. 22

    응용 프로그램에서 게시하지 않은 Facebook 게시물을 프로그래밍 방식으로 삭제하는 방법은 무엇입니까?

  23. 23

    백그라운드에서 BREW 응용 프로그램을 시작하는 방법은 무엇입니까?

  24. 24

    사용자가 그래픽 응용 프로그램을 시작하기 위해 일반 sudo를 사용해서는 안되는 이유는 무엇입니까?

  25. 25

    사용자가 그래픽 응용 프로그램을 시작하기 위해 일반 sudo를 사용해서는 안되는 이유는 무엇입니까?

  26. 26

    Android에서 응용 프로그램을 시작할 때마다 알림 수신을 중지하는 방법은 무엇입니까?

  27. 27

    Android에서 동적으로 버튼을 만들려고 할 때 내 응용 프로그램이 작동하지 않는 이유는 무엇입니까?

  28. 28

    시작 응용 프로그램 기본 설정에서 응용 프로그램을 추가하는 명령은 무엇입니까?

  29. 29

    @Transactional 롤백 봄 부팅 응용 프로그램에서 작동하지 않는 이유는 무엇입니까?

뜨겁다태그

보관