서로다른 앱을 내부액티비티(명시적 인텐트)로 쓰는법
조회수 1183회
안녕하세요 안드로이드 초보입니다.
건강정보앱을 만드는중인데 만보기 기능, 지도 기능은 구글에서 찾아서 새로 앱을 만들었고 제가 만든 앱에서 버튼 클릭시 외부 액티비티로 받아오는것은 쉽게 했습니다. 그러나 이걸 하나의 앱으로 합치고 싶어서 새로운 액티비티를 만들어 java문과 xml문을 똑같이 넣고 명시적 인텐트를 활용하여 실행해 보았는데 실행이 안됩니다..
제 생각엔 클래스가 여러개인 앱을 내부 액티비티로 활용하려고 했기 때문인것 같은데 실행 할 수 있는 방법이 없을까요?
자바 소스
package com.example.administrator.healthfit4;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void mOnClick(View view) {
Intent intent;
switch (view.getId()) {
case R.id.etc:
intent = new Intent(this, Bone.class);
startActivity(intent);
break;
case R.id.food:
intent = new Intent(this, Bone.class);
startActivity(intent);
break;
case R.id.option:
intent = new Intent(this, Body.class);
startActivity(intent);
break;
case R.id.manbogy:
intent = new Intent(this, Manbo.class);
startActivity(intent);
break;
case R.id.bicycle:
intent = new Intent(this, Map.class);
startActivity(intent);
break;
case R.id.health:
intent = new Intent(this, Health.class);
startActivity(intent);
break;
}
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.administrator.healthfit4.MainActivity">
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/mainimage"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/etc"
android:layout_width="73dp"
android:layout_height="65dp"
android:layout_marginStart="16dp"
android:layout_marginTop="128dp"
android:alpha="0.5"
android:onClick="mOnClick"
android:text="Button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/food"
android:layout_width="73dp"
android:layout_height="65dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="128dp"
android:alpha="0.5"
android:onClick="mOnClick"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/option"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="142dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:alpha="0.5"
android:onClick="mOnClick"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/bicycle"
app:layout_constraintEnd_toStartOf="@+id/manbogy"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etc"
app:layout_constraintVertical_bias="0.507" />
<Button
android:id="@+id/manbogy"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:alpha="0.5"
android:onClick="mOnClick"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/health"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/option"
app:layout_constraintTop_toBottomOf="@+id/food" />
<Button
android:id="@+id/bicycle"
android:layout_width="73dp"
android:layout_height="65dp"
android:layout_marginBottom="44dp"
android:layout_marginStart="16dp"
android:alpha="0.5"
android:onClick="mOnClick"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/health"
android:layout_width="73dp"
android:layout_height="65dp"
android:layout_marginBottom="52dp"
android:layout_marginEnd="16dp"
android:alpha="0.5"
android:onClick="mOnClick"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
매니패스트
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.administrator.healthfit4">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<meta-data
android:name="com.kakao.sdk.AppKey"
android:value="4d42888ec48781b6c0cc8f3c294b802a" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity
android:name=".LegRase"
android:configChanges="orientation|screenSize"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity
android:name=".Health"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity
android:name=".Abdomen"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity
android:name=".Back"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity
android:name=".Shoulder"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity
android:name=".Chest"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity
android:name=".Upperlimb"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity
android:name=".Lowerbody"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity android:name=".Body" />
<activity android:name=".Bone" />
<activity android:name=".Ear" />
<activity android:name=".Etc" />
<activity android:name=".Eye" />
<activity android:name=".Head" />
<activity android:name=".Heart" />
<activity android:name=".Intestine" />
<activity android:name=".Joint" />
<activity android:name=".Liver" />
<activity android:name=".Lung" />
<activity android:name=".Mouth" />
<activity android:name=".Nose" />
<activity android:name=".Organ" />
<activity android:name=".Stomach" />
<activity android:name=".Map"></activity>
</application>
</manifest>
댓글 입력