I'm having issues with a MapView.. I've used MapView's before so I really don't know what the problem is, it's probably something simple that I'm overlooking but it's driving me insane. The app installs and runs fun, but the MapView tiles do no load. All I see is an empty grid. I know the API key (debug keystore) is fun because I have another project using it that works perfectly. I've included my manifest, layout, and activity files to help diagnose the problem. I'd appreciate any help - I'm baffled!
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.***.studybuddy"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".StudyBuddy"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapInterface" >
</activity>
<service
android:name=".FriendService" >
<intent-filter>
<action
android:name="com.***.studybuddy.FriendService" />
</intent-filter>
</service>
</application>
layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/sideMenuInterface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
</LinearLayout>
<LinearLayout
android:id="#+id/mapInterface"
android:layout_alignLeft="#id/sideMenuInterface"
android:layout_alignTop="#id/sideMenuInterface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/topMenu"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:clickable="true"
android:onClick="onClick" >
</RelativeLayout>
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0f6nuBOcz_OlhAQm3B3Xljy5hDOVrR1FO3KM***"
/>
</LinearLayout>
</RelativeLayout>
activity:
package com.***.studybuddy;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class MapInterface extends MapActivity implements OnClickListener {
static int USER_ID = 1;
static MapView mapView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapinterface);
configure();
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
private void configure() {
findViews();
startService(new Intent(FriendService.class.getName()));
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(true);
}
private void findViews() {
mapView = (MapView) findViewById(R.id.mapView);
}
#Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.topMenu:
((View)view.getParent()).setVisibility(View.GONE);
break;
}
}
}
Screenshot:
I once had the problem that I missed some permissions. I need this 3 permissions (you are missing the first two of them.):
<uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION”></uses-permission>
<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”></uses-permission>
<uses-permission android:name=”android.permission.INTERNET”></uses-permission>
Related
I have developed an app for page navigation . when a button is clicked the page should navigate to the second page. when i run the project and opened my app its showing unfortunately API demo has stopped. I have posted the entire code of my app . PLS HELP ME OUT...
//MAIN ACTIVITY
<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="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginLeft="73dp"
android:layout_marginTop="14dp"
android:text="Click" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_alignParentTop="true"
android:layout_marginLeft="14dp"
android:layout_marginTop="34dp"
android:text="Main Activity" />
</RelativeLayout>
//SECONDSCREEN ACTIVITY
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sceond Screen Activity"
tools:context=".SecondScreenActivity"/>
</LinearLayout>
//JAVA CODE FOR MAIN ACTIVITY
package com.example.navigate;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addButtonOnClickEventListener();
}
public void addButtonOnClickEventListener()
{
Button button = (Button)findViewById(R.id.button1);
final Context context = this;
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,SecondScreenActivity.class);
startActivity(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
// JAVA CODE FOR SECOND SCREEN ACTIVITY
package com.example.navigate;
import android.app.Activity;
public class SecondScreenActivity extends Activity {
}
// MANIFEST FILE
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.navigate"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.navigate.SecondScreenActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name = "android.intent.action.MAIN"/>
<category android:name = "android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
First problem MainActivity is your launcher page here but you define the secondactivity as luncher in manifest.change it first.
Add an oncreate() to secondactivity otherwise there is nothing to show when the button click.
Third change your MainActivity Context to activity which is MainActivity.this not local
Other things are fine , and hope you understand your small problems..
Change your manifest to something like this:
// MANIFEST FILE
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.navigate.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name = "android.intent.action.MAIN"/>
<category android:name = "android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name = ".SecondScreenActivity" />
</application>
And in your SecondScreenActivity add an oncreate method with the contet view like:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondactivity_layout);
}
And also in your mainactivity change the context to MainActivity.this . Here you define the context inside onclicklistener which links to your local method not the class.
I am trying to start new activity using an intent but it never works.
two activities
MainActivity.java
Play.java
two layouts
activity_main.xml
layoutplay.xml
it shows THE APPLICATION HAS STOPPED UNEXPECTEDLY
where is the mistake?
MainActivity.java
package com.example.xxx;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Typeface t= Typeface.createFromAsset(getAssets(), "font.ttf");
TextView tv1= (TextView) findViewById(R.id.textView1);
tv1.setTypeface(t);
tv1.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if(v.getId()==R.id.textView1){
Intent i=new Intent(MainActivity.this,Play.class);
MainActivity.this.startActivity(i);
}
}
}
Play.java
package com.example.xxx;
import android.os.Bundle;
import android.app.Activity;
public class Play extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layoutplay);
}
}
activity_main.xml
<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="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:src="#drawable/bouncemenuback"
android:contentDescription="#string/menuback" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
style="#style/my"
android:text="#string/Play"/>
</LinearLayout>
</RelativeLayout>
layoutplay.xml
<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="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".Play" >
</RelativeLayout>
xxx.manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="9" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.xxx.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.xxx.Play"
android:label="#string/title_activity_play" >
/>
</activity>
</application>
</manifest>
try by removing unused /> inside <activity android:name="com.example.xxx.Play" ..... > /> </activity> in your AndroidManifest.xml
so your code should be :
<activity
android:name="com.example.xxx.Play"
android:label="#string/title_activity_play" >
</activity>
Try replacing your manifest code with this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="9" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.xxx.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.xxx.Play"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.PLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Hope this helps :)
Happy New Year All,
New with implementing Fragments in Android (and I have seen similar posts but I have not been able to get an answer for my problem), so here goes:
I wish to use SupportMapFragment (referenced from the support library v4) and I have created a class that extends FragmentActivity, called TripSummary.java:
package com.project.locationapp;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class TripSummary extends android.support.v4.app.FragmentActivity {
private GoogleMap mMap;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, LocationService.class);
stopService(intent);
setContentView(R.layout.activity_trip_summary);
createMap();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_trip_summary, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
//Content?
return super.onOptionsItemSelected(item);
}
private void createMap(){
//if a map has not already been instantiated it'll return null
if(mMap == null){
//instantiate map
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//check it has been instantiated
if(mMap != null){
Toast.makeText(this, "map done", Toast.LENGTH_SHORT)
.show();
//Manipulate map here (add coordinates/polylines from trip etc etc.)
}
}
}
}
Which gets a layout from activity_trip_summary.xml
<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" >
<TextView
android:id="#+id/tripSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/trip_summary"
tools:context=".Start" />
<TextView
android:id="#+id/tripDetails"
android:layout_below="#id/tripSummary"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/awaiting_location"
tools:context=".Start" />
<Fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_below="#id/tripDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
AndroidManifest.xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project.locationapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<permission
android:name="com.project.locationapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.project.locationapp..permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<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_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.project.locationapp.Start"
android:label="#string/title_activity_start" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.project.locationapp.LocationService" />
<activity
android:name="com.project.locationapp.TripSummary"
android:label="#string/title_activity_trip_summary" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.project.locationapp.Start" />
</activity>
<activity
android:name="com.project.locationapp.ViewTrips"
android:label="#string/title_activity_view_trips" >
</activity>
<activity
android:name="com.project.locationapp.TripDetail"
android:label="#string/title_activity_trip_detail" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<-- My Key -->"/>
</application>
</manifest>
The problem I am having in that each time I try to load the activity TripSummary, I get a 'Sorry! stopped unexpectedly' dialog and the app crashes.
LogCat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.locationapp/com.project.locationapp.TripSummary}: android.view.InflateException: Binary XML file line #24: Error inflating class Fragment
I am referencing the google-play-services_lib library (which is also in my workspace) and I also have a copy of android-support-v4.jar in /libs directory within my project.
If you know an answer to my problem, please share!
Thanks in advance.
Please replace:
<Fragment
with:
<fragment
Also, you can get rid of the redundant/incorrect namespace declarations in that element.
Also also, in the future, post the complete stack trace, not just part of one line, to make it easier for people to help you.
I have a problem with an Android aplication. When I try to swich from main activity (PretvornikValut) to another one (Pretvornik) via buttun I get the "Unfortunately aplication stopped working" error. Can anyone help?
PretvornikValut.java
package pretvornik.valut;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class PretvornikValut extends Activity implements OnClickListener
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View gumbPretvori = findViewById(R.id.gumb_pretvornik);
gumbPretvori.setOnClickListener(this);
View gumbTecaji = findViewById(R.id.gumb_tecaji);
gumbTecaji.setOnClickListener(this);
}
public void sendMessage(View view) {
Intent intent = new Intent(this, Pretvornik.class);
startActivity(intent);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.gumb_pretvornik:
Intent i = new Intent(this, Pretvornik.class);
//i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
break;
case R.id.gumb_tecaji:
Intent tecaj = new Intent(this, Tecaji.class);
tecaj.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(tecaj);
break;
}
}
}
Pretvornik java
package pretvornik.valut;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
/**
*
* #author FAKS
*/
public class Pretvornik extends Activity {
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.pretvornik);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#99CCCC"
>
<Button
android:id="#+id/gumb_pretvornik"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="Pretvornik"
/>
<Button
android:id="#+id/gumb_tecaji"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_toRightOf="#+id/OK"
android:layout_alignParentBottom="true"
android:text="Izpis tecajev"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Izberi zeljeno opcijo"
/>
</LinearLayout>
pretvornik.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#99CCCC"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="glavni program"
/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pretvornik.valut"
android:versionCode="1"
android:versionName="1.0">
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<activity android:name="PretvornikValut"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name="Pretvornik"
android:label="#string/Pretvornik_valut" >
<meta-data
android:name="PretvornikValut"
/>
</activity>
<activity
android:name="Tecaji"
android:label="#string/Izpis_tecajev" >
<meta-data
android:name="PretvornikValut"
/>
</activity>
</activity>
</application>
</manifest>
Change your manifest xml,
add action for your activities
action android:name="android.intent.action.ACTIVITY"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pretvornik.valut"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="PretvornikValut"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="Pretvornik"
android:label="#string/hello_world" >
<action android:name="android.intent.action.ACTIVITY" />
</activity>
<activity
android:name="Tecaji"
android:label="#string/hello_world" >
<action android:name="android.intent.action.ACTIVITY" />
</activity>
</application>
</manifest>
My app has three tabs, one of which is a Map. From the other two tabs I want the user to be able (after navigation through several screens) to go to the map tab and a certain location on the map with a button click from one of the screens which the user ends up on from the other two tabs. Is this possible?
referenced from method intentTest.xyz.com.intentTest$1.onClick
1.intentTest.java:
package intentTest.xyz.com;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class intentTest extends Activity {
Button b;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b = (Button) findViewById(R.id.b);
b.setOnClickListener( new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(intentTest.this,second.class );
startActivity(intent);
}
});
}
}
2.main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="First screen"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="map"
android:id="#+id/b"
/>
</LinearLayout>
3.second.java:
package intentTest.xyz.com;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class second extends MapActivity{
MapView map;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
map = (MapView) findViewById(R.id.map);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
4.second.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0ujyc9Tw2cYvyPECIKTQIK0pwuL-UPa_sh4BpIw"
/>
5.manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="intentTest.xyz.com"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".intentTest"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".second"
android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>