Android: Activity not found when starting new activity using intent - android

I am trying to launch a new activity from within an existing activity however I get an activity not found exception.
Here is a stripped back version of my code and the logcat error. Any help would be really appreciated.
MainActivity
public class MainActivity extends FragmentActivity {
/* (non-Javadoc)
* #see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivity(new Intent(this, TermsAndConditions.class));
}
....
}
NewActivity
public class TermsAndConditions extends Activity{
/* (non-Javadoc)
* #see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.terms_and_conditions);
}
}
Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:screenOrientation="sensorLandscape">
<activity
android:name=".MainActivity"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation"
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:label="#string/app_name" android:name=".TermsAndConditions"></activity>
</application>
</manifest>
Logcat
04-02 16:48:43.255: E/AndroidRuntime(20856): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.app/com.example.app.TermsAndConditions}; have you declared this activity in your AndroidManifest.xml?

<activity android:label="#string/app_name" android:name="com.example.app.TermsAndConditions"></activity>
and clean your project,
Hope this help you.

The problem is, you've told the Main Activity to send the intent but you haven't told the Terms and Conditions activity to receive the intent. You do that by, in the onCreate method in the Ts and Cs page go getIntent() after setContentView

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 ActionBar is hidden with DroidGap (PhoneGap/ Cordova)

i just spent some hours on making the Actionbar visible without success:
With my RegisterActivity i collect some login data and then i start MainActivity. In RegisterActivity i have a Actionbar but not in MainActivity:
AndroidManifest:
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="17"/>
<application android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity android:name="RegisterActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="MainActivity"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:theme="#android:style/Theme.Holo" >
</activity>
</application>
RegisterActivity:
...
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.putExtra("username", username);
i.putExtra("password", password);
startActivity(i);
...
MainActivity:
...
webview = new WebView(this);
setContentView(webview);
webview.loadUrl(address);
...
Normally there should be an Actionbar but there isn't!
just hope that someone has a solution for my problem?!
Thanks
I solved my problem:
My RegisterActivity extends the Class Activity! My MainActivity extends the class DroidGap from Phonegap2.5.0 (aka Apache Cordova).
I changed MainActivity so that it extends Activity and the result is that the ActionBar is visible :D
When you need DroidGap you will have to insert
super.setBooleanProperty("showTitle", true);
before you call:
super.onCreate(savedInstanceState);
At the end it looks like this:
public class MainActivity extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.setBooleanProperty("showTitle", true);
super.onCreate(savedInstanceState);
//More Code ....
The correct way of setting the boolean property ShowTitle is using the preferences in the config.xml.
add
<preference name="ShowTitle" value="true"/>
to config.xml to enable the ActionBar on Android.
Are you sure that there is no line:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
in onCreate() method?
Try:
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
...
setContentView(...);
...
or
...
this.requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
...

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...

Switch from Android Activity to MapActivity

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

Categories

Resources