0

This may be a very stupid question. But, I stuck in a place where tried to add a normal screen to my Maps Activity.

Here is my activity_maps.xml file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dip"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
tools:context=".MapsActivity">

<Button
    android:id="@+id/btnLoc1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btnCity"
    android:layout_alignParentTop="true"
    android:onClick="onClick_Loc1"/>

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_below="@+id/btnLoc1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

<Button
    android:id="@+id/btnCity"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btnLoc2"
    android:layout_alignParentTop="true"
    android:onClick="onClick_City"/>

<Button
    android:id="@+id/btnLoc2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:onClick="onClick_Loc2"/>

<Button
    android:id="@+id/removeMarker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:onClick="onClick_Remove"/>

<CheckBox
    android:id="@+id/checkRestaurants"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btnLoc1"
    android:layout_alignParentTop="true"
    android:text="Restaurants" />
<CheckBox
    android:id="@+id/checkHotels"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/checkRestaurants"
    android:layout_alignParentTop="true"
    android:text="Hotels" />

Here is my normal.xml file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dip"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
tools:context=".MapsActivity">

<Button
    android:id="@+id/activity_button"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:background="@color/ripple_material_light"
    android:layout_marginTop="20dp"
    android:layout_marginRight="15dp"
    android:layout_marginLeft="15dp"
    android:textColor="#fff"
    android:textStyle="bold"
    android:text="Button" />

Here is my Manifest.

<?xml version="1.0" encoding="utf-8"?>

<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" />

<permission
    android:name="com.example.manuli.mymapnew.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.manuli.mymapnew.permission.MAPS_RECEIVE" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

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

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".NormalActivity"
        android:label="@string/title_activity_normal" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

What I need to do is when I'm loading the app I want to redirect to the normal screen. when I click the button in the normal screen, I need to redirect to the map page.

Here is my normal.java class.

    package com.example.manuli.mymapnew;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class NormalActivity extends ActionBarActivity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_normal, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

How do I edit the code to load this normal page first and load the map page after clicks on the button?

4 Answers4

0

make sure your activity is in manifest file cut and paste:

<intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

in normal activity in manifest file.

Asif Sb
  • 785
  • 9
  • 38
  • I did right click on layout and add a new layout resource file. But, manifest shows only the MapsActivity. Where should I paste it? –  Oct 08 '15 at 11:12
  • refer this http://stackoverflow.com/questions/2337874/best-way-to-add-activity-to-an-android-project-in-eclipse – Asif Sb Oct 08 '15 at 11:16
  • Added the intentfilter and edited the answer. Can You just check it? It is not working. Still the map page loaeding first –  Oct 08 '15 at 11:28
0

just remove

<intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

from

<activity
        android:name=".MapsActivity"

section in your manifest file

DGN
  • 702
  • 3
  • 12
0

Replace your manifest's application section with below code.

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

     <activity
       android:name=".NormalActivity"
       android:label="@string/title_activity_normal" >
       <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
     </activity>

     <activity
       android:name=".MapsActivity"
       android:label="@string/title_activity_maps" >
     </activity>
</application>
BhagyaNivi
  • 741
  • 6
  • 12
0

I think you should call an intent what opens MapsActivity class. Create Button clicklistener function and it should startnewactivty.

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {Intent i = new Intent(this, MapsActivity .class );
    startActivity(i);}

}

alican akyol
  • 303
  • 3
  • 14
  • Can you tell me where to add this in NormalActivity.java? –  Oct 08 '15 at 11:47
  • After the setContentView function. You add that; Button open = (Button)findviewbyid(R.id.activity_button); Then add above code which is written by me. – alican akyol Oct 08 '15 at 11:54