so here is another basic problem i’m having…my application crashes as i try to pass a string to another activity. i have tried a few ways but in vain. here’s the code
Main Activity named Main.java
package com.ammad.test;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Main extends Activity {
TextView tv;
Button b1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tvShow);
b1 = (Button) findViewById(R.id.bt1);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Bundle basket = new Bundle();
String myScore = "testing";
basket.putString("key", myScore);
Intent intent = new Intent(Main.this, Second.class);
intent.putExtras(basket);
startActivity(intent);
}
});
}
}
Second class to which the data is passes named Second.java
package com.ammad.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Second extends Activity{
TextView tv;
String getScore;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
tv= (TextView) findViewById(R.id.tvRes);
Bundle gotBasket = getIntent().getExtras();
getScore = gotBasket.getString("key");
tv.setText(getScore);
}
}
and finally the manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ammad.test"
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=".Main"
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>
<activity
android:name=".Sec"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="com.ammad.test.SECS" />
</intent-filter>
</activity>
</application>
</manifest>
Seems to me your second activity is declared wrong in the manifest, as .Sec not .Second as would be expected – the log is probably showing a exception because the intent was invalid.