Switch from Android Activity to MapActivity - android

I am developing an Android app, in which I have to move to MapActivity on Button click event.
But the app is crashing while switching from Activity to MapActivity.
can anyone help me on this?
Thanks in advance.
Here is my code,
public class PopupActivity extends Activity implements GPSCallback
{
.......
public void display_map(String str)
{
Intent showMap_intent = new Intent(this,DisplayGoogleMaps.class);
PopupActivity.this.startActivity(showMap_intent);
}
}
This is my map Activity class
public class DisplayGoogleMaps extends MapActivity
{
MapView mapView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
}
}
And This is my Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:label="#string/app_name"
android:name=".PopupActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".DisplayGoogleMaps" >
</activity>
</application>
</manifest>
there is nothing in error log while crashing!

Did you declare the map activity in your Manifest? Did you set the Android API package as Google APIs ?
These are mandatory.

What do you mean with "while switching from Activity to MapActivity"?
How do you switch? Any source code?
When you want to show some data in am MapView you have to start an Intent.
public void onClick(View view) {
Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
i.putExtra("Value2", "This value two ActivityTwo");
// Set the request code to any code you like, you can identify the
// callback via this code
startActivity(i);
}
From http://www.vogella.de/articles/AndroidIntent/article.html => 6. Tutorial: Explicit intents and data transfer between activities
In your case the class >ActivityTwo< has to be the MapActivity

Related

Application crashes upon new Activity

I know and I do understand that this question has been asked, but I can't seem to interpret it for my application. I am creating an application - using Android Studio - that opens a Activity (called 'About'). When a user clicks on the 'about button' on my MainActivity, it should launch the 'About' activity. However, when I test this out on my device, it says the app has stopped. And on my output panel, it says something about an error with my Manifest.xml file?
MainActivity:
package com.msp.supercarsounds;
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 clickedAbout(View view) {
final int result = 1;
Intent AboutButtonClicked = new Intent (this, About.class);
AboutButtonClicked.putExtra("About", "MainActivity");
startActivityForResult(AboutButtonClicked, result);
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msp.supercarsounds">
<uses-sdk android:minSdkVersion="17"
android:targetSdkVersion="22"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thank you for your help and time!
You have to declare About activity
<activity android:name=".About">
</activity>
Add this below the </activity> tag of MainActivity
your second activity "about" is not added to manifest.xml add this under the mainactivity
<activity android:name=".about">/activity>

Sending notification from one app to another app in Android

I am creating android application for sending notification. I have create two Android application. Here I want to send some forms details via notification from first Android application to 2nd android application in Android.
And after that receiving the notification, click on the notification I want to open my second Android application. What should be done to send the push notification to the particular individual user in Android?
Here is my Activity one codes
public class Activity_One extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_one);
Button btn =(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.customer.Activity_One","com.vendor.Activity_B"));
startActivity(intent);
}
});
}
}
Here is AndroidManifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.customer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Activity_One"
android:label="#string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is Activity two code
public class Activity_B extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_two);
Button bn = (Button)findViewById(R.id.button1Send);
bn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setAction("com.customer.Activity_One");
startActivity(intent);
}
});
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vendor"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Activity_B"
android:label="#string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action
android:name="com.vendor.Activity_B" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You do not need to use notifications at all. You can just use intents. That is the standard way to accomplish what you want to achieve. See Interacting with Other Apps for details.
From first application you can start a normal notification and from second application initialize a broadcast receiver and read notification

Android Studio, error with intents

I'm using Android Studio to write and run my android application but I run into this error when I try to go from one activity to another via intent, I either get this error:
android.content.ActivityNotFoundException: Unable to find explicit activity class
{com.example.rudrunk/junit.framework.Test}; have you declared this activity in your
AndroidManifest.xml?
or a NullPointerException if I use another intent.
My manifest file is below, but all the code comes from the IDE automatically, so I don't understand what's going on.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rudrunk"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:theme="#style/AppTheme" android:label="#string/app_name" android:icon="#drawable/ic_launcher" android:debuggable="true" android:allowBackup="true">
<activity android:label="#string/app_name" android:name="com.example.rudrunk.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/title_activity_test" android:name="com.example.rudrunk.Test" />
<activity android:label="#string/title_activity_drunk_test" android:name="com.example.rudrunk.DrunkTest" />
</application>
Java Code for intents:
final Intent localIntent1 = new Intent(MainActivity.this, DrunkTest.class);
final Intent localIntent2 = new Intent(MainActivity.this, Test.class);
Button localButton1 = (Button)findViewById(R.id.maybe);
Button localButton2 = (Button)findViewById(R.id.yes);
localButton1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
startActivity(localIntent1);
}
});
localButton2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View paramAnonymousView)
{
Intent localIntent = new Intent("android.intent.action.CALL");
localIntent2.setData(Uri.parse("tel:16097212155"));
startActivity(localIntent2);
}
});
Looks like Test.class is being resolved into junit.framework.Test instead of your Activity. This could be a wrong import (import junit.framework.Test;?) but the sure way to make it work would be to use the full class name, i.e.
new Intent(MainActivity.this, com.example.rudrunk.Test.class);
In any case, it should match the class name in the AndroidManifest file.

Why Button click redirection for another xml page is not working?

I looked in to everything before ask this. I am implementing an application and new to android, I need to redirect to my mapview xml when login button click. So i have written the intent plus made the activity in manifest file and tried writing codes every possible different way. And the code doesn't give any errors. But my emulator stops after launching.
I know something is wrong but I can't figure it out. Any idea why that happens?
here is my code
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button=(Button)findViewById(R.id.loginbtn);
button.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
switch (v.getId()) {
case R.id.loginbtn:
Intent intent = new Intent (MainActivity.this, MapView.class);
startActivity (intent);
break;
default:
break;}
}
}
);
}
}
/*if(username.getText().toString()==""&&password.getText().toString()=="")
{
Intent i= new Intent("com.example.shaz.MAPVIEW");
startActivity(i);
}
else
{
txt.setText("False");
}
*/
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myname"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.myname.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=".mapView"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.myname.MAPVIEW" />
<category android:name="android.intent.category.DEFUALT" />
</intent-filter>
</activity>
</application>
</manifest>
I have also created an xml file for map called map_view in my layouts.
So in every where I searched this is how they say new intent is creating .
And the emulator works fine if I do something else than this redirection. SO what ever problem I got is within this redirection part.
DEFAULT is spelled incorrectly in your Manifest
Change:
<category android:name="android.intent.category.DEFUALT" />
for this:
<category android:name="android.intent.category.DEFAULT" />

Activity won't start a service

I m trying to start an IntentService from the main activity of y application and it won't start. I have the service in the manifest file. Here's the code:
MainActivity
public class Home extends Activity {
private LinearLayout kontejner;
IntentFilter intentFilter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
kontejner = (LinearLayout) findViewById(R.id.kontejner);
intentFilter = new IntentFilter();
startService(new Intent(getBaseContext(), HomeService.class));
}
}
Service:
public class HomeService extends IntentService {
public HomeService() {
super("HomeService");
// TODO Auto-generated constructor stub
}
#Override
protected void onHandleIntent(Intent intent) {
Toast.makeText(getBaseContext(), "TEST", Toast.LENGTH_LONG).show();
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.salefinder"
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=".Home"
android:label="#string/title_activity_home" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".HomeService" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
How can I make it work?
onHandleIntent gets called from a background thread. You can't modify the UI, or in this case, make Toast from outside the UI thread. So, I wouldn't expect anything to happen with your service.
Just try writing something out with Log.d() to see if your service is getting called.
It seams that android cached a bad version of the app - I forced closed it and started it again, and it worked...

Categories

Resources