Android activity is not started with any exception - android

I have created different activities with no problems so far, however, I have created now an activity called DetailsActivity that is not launched, with no exception, it just does not open (onCreate event is not getting called).
This is the manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.camera" android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_tdc"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".activities.MainActivity"
android:label="#string/app_title"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.FormActivity"
android:parentActivityName=".activities.MainActivity"
android:theme="#style/AppTheme" >
</activity>
<activity
android:name=".activities.GalleryActivity"
android:parentActivityName=".activities.FormActivity"
android:theme="#style/AppTheme" >
</activity>
<activity
android:name=".activities.DetailsActivity"
android:parentActivityName=".activities.GalleryActivity"
android:theme="#style/AppTheme" >
</activity>
</application>
This is the java class of the Activity:
package cl.virtualice.tdc.activities;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;
import cl.virtualice.tdc.R;
/**
* Created by Jaime on 23-10-2015.
*/
public class DetailsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
String title = getIntent().getStringExtra("title");
Bitmap bitmap = getIntent().getParcelableExtra("image");
TextView titleTextView = (TextView) findViewById(R.id.title);
titleTextView.setText(title);
ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.setImageBitmap(bitmap);
}
}
And finally, this is the code that tries to launch the activity:
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
ImageGalleryItem item = (ImageGalleryItem) parent.getItemAtPosition(position);
//Create intent
Intent intent = new Intent(GalleryActivity.this, DetailsActivity.class);
intent.putExtra("title", item.getTitle());
intent.putExtra("image", item.getImage());
//Start details activity
startActivity(intent);
}
Any help will be appreciated, thanks.

You need to add those intents to a bundle and then unpack them in onCreate.
You put the Title as and extra and then write over it with the bitmap. Then in onCreate you try to get the title which was overwritten. I would be that it does not exist as an extra.
Bundle b = new Bundle();
b.putString("TITLE", item.getTitle);
b.putParcelable("BITMAP", item.getImage());
intent.putExtras(b);

Related

ActivityNotFoundException - Send Intent between two apps

I am trying to send an intent from the MainActivity of App A to the MainActivity of App B and then bring the App B to the front but when starting the App A I am getting the following error:
Caused by: android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=com.example.app.MainActivity
pkg=com.example.app (has extras) }
First, I am starting the App B and then the App A.
How can I send an intent from the MainActivity of app A to the MainActivity of app B and then bringing the app B to the front ?
App A MainActivity:
package com.mysender;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String pdfString = "Hello World";
final Intent intent= new Intent("com.example.app.MainActivity");
intent.setPackage("com.example.app");
intent.putExtra("path", pdfString);
startActivity(intent);
}
}
App A Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mysender">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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=".MainActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
App B MainActivity:
package com.example.app;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
private WebView mWebView;
//private BroadcastReceiver myReceiver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle data = getIntent().getExtras();
if(data!=null){
String myString = data.getString("Id");
Toast.makeText(this,"Data Received from External App: " , Toast.LENGTH_SHORT).show();
}
}
App B Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="com.example.app.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>
</application>
</manifest>
Error:
Caused by: android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=com.example.app.MainActivity
pkg=com.example.app (has extras) }
final Intent intent= new Intent("com.example.app.MainActivity");
intent.setPackage("com.example.app");
intent.putExtra("path", pdfString);
startActivity(intent);
Caused by: android.content.ActivityNotFoundException: Unable to find
explicit activity class
{com.example.app/com.example.app.MainActivity}; have you declared this
activity in your AndroidManifest.xml?
final Intent intent= new Intent();
intent.setComponent(new ComponentName("com.example.app", "com.example.app.MainActivity"));
intent.putExtra("path", pdfString);
startActivity(intent);
Edit:
I have changed my manifest B to the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="com.mysender.Data"/>
</intent-filter>
</activity>
</application>
</manifest>
And the MainActivity of App A to:
package com.mysender;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String pdfString = "Hello World";
final Intent intent= new Intent("com.example.app.MainActivity");
intent.setPackage("com.example.app");
intent.setAction("com.mysender.Data");
intent.putExtra("path", pdfString);
startActivity(intent);
}
}
but I am still getting the error:
Caused by: android.content.ActivityNotFoundException: No Activity
found to handle Intent { act=com.mysender.Data pkg=com.example.app
(has extras) }

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>

Android Splash screen cannot load another activity

The following is the code for my Android splash screen activity.
When it attempts to load another activity, the application crashes on Android 4.0 and 4.1.
I have no idea what's causing this because when it crashes, it does not log any error.
Has anyone come across anything like this befere?
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import org.bitbucket.infovillafoundation.denko.R;
import org.bitbucket.infovillafoundation.denko.component.DaggerDenkoStationComponent;
import org.bitbucket.infovillafoundation.denko.component.DenkoStationComponent;
import org.bitbucket.infovillafoundation.denko.models.DenkoModel;
import org.bitbucket.infovillafoundation.denko.module.DenkoStationModule;
import org.bitbucket.infovillafoundation.denko.service.DenkoStationService;
import butterknife.ButterKnife;
import butterknife.InjectView;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
public class SplashScreenActivity extends Activity {
#InjectView(R.id.imgLogo)
ImageView logoImage;
#InjectView(R.id.welcomeText)
TextView welcomeText;
private Handler splashHandler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Runnable r = new Runnable() {
#Override
public void run() {
//********************* application is crashing here
Intent mainIntent = new Intent(SplashScreenActivity.this, LanguageOptionActivity.class);
startActivity(mainIntent);
finish();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
};
setContentView(R.layout.activity_splash);
ButterKnife.inject(this);
DenkoStationComponent component = DaggerDenkoStationComponent.builder().denkoStationModule(new DenkoStationModule()).build();
final DenkoStationService denkoStationService = component.provideDenkoStationService();
Callback<DenkoModel> callback = new Callback<DenkoModel>() {
#Override
public void success(DenkoModel denkoModel, Response response) {
toast(R.string.server_connection_successful);
denkoStationService.updateDatabaseWithDenkoModel(denkoModel);
}
#Override
public void failure(RetrofitError error) {
toast(R.string.server_connection_failed);
}
public void toast(int textId) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.toast_text);
text.setText(getResources().getString(textId));
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
};
denkoStationService.fetchDenkoModel(denkoStationService.fetchDenkoLastDataState(), callback);
if (isNetworkAvailable())
splashHandler.postDelayed(r, 3000);
else {
toast(R.string.no_internet_connection);
splashHandler.postDelayed(r, 3000);
}
//********************* application is crashing here
Intent mainIntent = new Intent(this, LanguageOptionActivity.class);
startActivity(mainIntent);
}
#Override
protected void onResume() {
super.onResume();
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
private void toast(int textId) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.toast_text);
text.setText(getResources().getString(textId));
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
}
Edit: AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.bitbucket.infovillafoundation.denko">
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="org.bitbucket.infovillafoundation.denko.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="org.bitbucket.infovillafoundation.denko.MAPS_RECEIVE" />
<application
android:name=".application.DenkoApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".activity.SplashScreenActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.MainActivity"
android:label="#string/title_activity_home"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" />
<activity
android:name=".activity.LanguageOptionActivity"
android:label="#string/title_activity_language_option"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAubZsgoC4Z64qcOSpfK4grjrK5zrTEWxk" />
</application>
</manifest>
I think that since the crashes do not occur with a higher Android version, the problem might be resulting from an incompatible OpenGL version.
You can use following Activity with some simple content. Inject the layout (see below) and register in the layout file an onclick-listener (method "forward"). In this method you can call your next activity:
public class SplashScreen extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
}
public void forward(View v){
startActivity(new Intent(this, MainActivity.class), 0);
}
}
splashscreen.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
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:id="#+id/splashscreen"
android:onClick="forward"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Add in your AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name=".SplashScreen"
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=".MainActivity" />
</application>
The class "MainActivity" represents your main activity and the class "SplashScreen" represents a simple splash screen.
I hope this will help you:)
The problem i see is that while calling the activity tag you still use .activity in the name attribute
i.e you used android:name=".activity.MainActivity"
instead of android:name=".MainActivity" both for splash screen activity and main activity.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.bitbucket.infovillafoundation.denko">
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="org.bitbucket.infovillafoundation.denko.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="org.bitbucket.infovillafoundation.denko.MAPS_RECEIVE" />
<application
android:name=".application.DenkoApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreenActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar">
<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/title_activity_home"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" />
<activity
android:name=".activity.LanguageOptionActivity"
android:label="#string/title_activity_language_option"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAubZsgoC4Z64qcOSpfK4grjrK5zrTEWxk" />
</application>
</manifest>
I think you cannot added your splash screen in AndroidManifest.xml.plz check
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread logoTimer = new Thread() {
public void run() {
try {
int logoTimer = 0;
while (logoTimer < 500) {
sleep(100);
logoTimer = logoTimer + 100;
}
Intent newIntent = new Intent(Splash.this, MainActivity.class);
startActivity(newIntent);
} catch(InterruptedException e) {
e.printStackTrace();
} finally {
finish();
}
}
};
logoTimer.start();
}
}
in Android Manifest.xml
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

onCreate method not called in android

I have created 2 activities.When i call second activity from first via intent then onCreate method of second activity does not called.Although first activity's onCreate method is called normally as it should be.
Below is the code for first activity.
package com.webesperto.webespertofirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
int counter;
Button add, sub;
TextView tView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
tView = (TextView) findViewById(R.id.textView1);
// Intent in = new Intent(AC);
add.setOnClickListener(this);
sub.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bAdd:
tView.setText(++counter + "");
try {
Intent nextIntentView = new Intent(MainActivity.this, ShowValueActivity.class);
nextIntentView.putExtra("key", "counter");
startActivity(nextIntentView);
}
catch (Exception e) {
e.printStackTrace();
}
break;
case R.id.bSub:
tView.setText(--counter + "");
break;
default:
break;
}
}
}
Code for second activity.
package com.webesperto.webespertofirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ShowValue extends Activity {
TextView tv_showValue1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_value);
tv_showValue1 = (TextView) findViewById(R.id.tv_showValue);
Intent gotIntent = (Intent) this.getIntent();
Bundle gotBundle = gotIntent.getExtras();
tv_showValue1.setText(gotBundle.getString("key"));
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webesperto.webespertofirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
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.webesperto.webespertofirstapp.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=".ShowValueActivity"
android:label="#string/title_activity_show_value" >
</activity>
</application>
</manifest>
you have
<activity
android:name=".ShowValueActivity"
android:label="#string/title_activity_show_value" >
</activity>
instead of
<activity
android:name=".ShowValue"
android:label="#string/title_activity_show_value" >
</activity>
Since your code reads
public class ShowValue extends Activity {
Though, why doesnt your application crash saying NoActivityFoundException ??
please have a look on manifest
change
<activity
android:name=".ShowValueActivity"
android:label="#string/title_activity_show_value" >
</activity>
to
<activity
android:name=".ShowValue"
android:label="#string/title_activity_show_value" >
</activity>
yours manifest should be like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webesperto.webespertofirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
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.webesperto.webespertofirstapp.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=".ShowValue"
android:label="#string/title_activity_show_value" >
</activity>
</application>
</manifest>
Change your Second Activity name in class file like this:
package com.webesperto.webespertofirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ShowValueActivity extends Activity {
TextView tv_showValue1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_value);
tv_showValue1 = (TextView) findViewById(R.id.tv_showValue);
Intent gotIntent = (Intent) this.getIntent();
Bundle gotBundle = gotIntent.getExtras();
tv_showValue1.setText(gotBundle.getString("key"));
}
}
It will work:)

Cannot load new blank activity - android tutorial

I am a new android developer and encountered a problem while following the tutorial on Android's site - http://developer.android.com/training/basics/firstapp/starting-activity.html
My program loads on the emulator fine, but when you type something into the EditText and then hit the send button, a window pops up saying "App has stopped working". It seems as though my new activity isn't being created and I'm not sure as to why. I've scoured the web (and my code) to see if I could get a solution but did so to no avail. Any help would be appreciated.
The code for my first activity:
package com.example.appli;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myapp.MESSAGE";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testlayout);
//////Button myButton = (Button) findViewById(R.id.my_button); //Told in tutorial to put this in onCreate
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
/** Called when the user selects the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
The code for my second activity (the one being called)
package com.example.appli;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class DisplayMessageActivity extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//get message from intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
}
}
The Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appli"
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="com.example.myapp.DisplayMessageActivity" />
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
In AndroidManifest File you have declared incorrect package
change
<activity android:name="com.example.myapp.DisplayMessageActivity" />
to
<activity android:name="com.example.appli.DisplayMessageActivity" />
or just
<activity android:name=".DisplayMessageActivity" />
you have declared only one Activity that's also wrong package name
already your manifest has the package name
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.appli"
so just declare like this
<activity android:name=".DisplayMessageActivity" />
and you need to add this in your manifest also
<activity android:name=".MainActivity />
remove the target SDK version that you mentioned
android:targetSdkVersion="15"
Try this
<activity android:name=".DisplayMessageActivity"/>
Instead of
<activity android:name="com.example.myapp.DisplayMessageActivity" />
in your Manifest.xml file.
You has defined the package package com.example.appli; in your activities.
Why have you defined you activity in manifest like <activity android:name="com.example.myapp.DisplayMessageActivity" />?
Replace this line with
<activity android:name=".DisplayMessageActivity" />.

Categories

Resources