I am new to android development. After setting up an android project, I tried to get text input and passe it to another activity (screen).
When I run the project I don't get an error but when I click the application it shows the first screen then when click the button in the screen it gives the error 'application stopped unexpectedly'.
When I try the code without passing data from first screen to second screen , the application works properly.
This is MainActivity.java file:
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.EditText;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText et= (EditText) findViewById(R.id.editText1);
Button b = (Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//intent class is used for activating another or component or an activity
Intent intent =new Intent(MainActivity.this, Second.class);
intent.putExtra("textval", et.getText().toString());
startActivity(intent);
}
});}}
Here is the code for Second.java file:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Second extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
TextView tv= (TextView) findViewById(R.id.textView1);
tv.setText(getIntent().getExtras().getString("textval"));
}
}
Here is the activitymain.xml code:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<EditText android:id="#+id/editText1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_alignParentTop="true"
android:ems="10"
android:inputType="text"
>
<requestFocus />
</EditText>
<Button android:id="#+id/button1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_below="#+id/editText1" android:layout_marginTop="28dp"
android:text="#string/button" />
</RelativeLayout>
Here is the second xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="#string/textview" />
</LinearLayout>
Please help me to find the error. Since I don't get an error notification I am not able to proceed.
Thanks in advance...
This is what you missed on your Second.java:
setContentView(R.layout.second);
put it above of your textview declaration.
In your Second java file make changes as follows
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Second extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
TextView tv= (TextView) findViewById(R.id.textView1);
tv.setText(getIntent().getExtras().getString("textval"));
}
}
Declare Second Activity in android manifest file .
<activity android:name=".Second"/>
Add setContentView(R.layout.second); in second activity.
Add entry for second activity in your Manifest file.
Put first activity as a Launcher and other as a Default.
Here I have two activity MainActivity and Player.
First I Launches MainActivity and then call other activity Player
Note- Activity name should be same as class name, so Keep same in Manifest file as well.
Also you need to specify the layout file for both activity by setContentView in onCreate function.
Here is sample code-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vt.soc"
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=".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>
<activity
android:name=".Player"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="com.vt.soc.PALYER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
- In your Second Activity you forgot to add the setContentView().
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
TextView tv= (TextView) findViewById(R.id.textView1);
tv.setText(getIntent().getExtras().getString("textval"));
}
- Please also do see that you have added this Second Activity in your Manifest.xml file.
Related
I have imported some code in android studio. The XML codes appear in the XML file resource but not in android device. My Main Activity is set in default and have no error.
<?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:background="#color/tan_background"
android:orientation="vertical" tools:context="com.example.android.miwok.MainActivity"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.android.com/apk/res/android ">
<TextView android:id="#+id/numbers"
style="#style/CategoryStyle"
android:background="#color/category_numbers"
android:text="#string/category_numbers"
android:onClick="openNumbersList"/>
<TextView android:id="#+id/family"
style="#style/CategoryStyle"
android:background="#color/category_family"
android:text="#string/category_family" />
<TextView android:id="#+id/colors"
style="#style/CategoryStyle"
android:background="#color/category_colors"
android:text="#string/category_colors" />
<TextView android:id="#+id/phrases"
style="#style/CategoryStyle"
android:background="#color/category_phrases"
android:text="#string/category_phrases" />
</LinearLayout>
And this is my Main Activity:
package com.example.android.miwok;
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 openNumbersList(View view){
Intent intent = new Intent(this,NumbersActivity.class);
startActivity(intent);
}
}
You say your MainActivity is set in DEFAULT. If that is referring to your manifest, please change it to this:
<activity
android:name="com.example.android.miwok.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>
You need a LAUNCHER activity in order for Android to know which Activity to launch when the app starts.
Set your xml file in your Activity as shown below:
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
and set the TextView text color to black
android:textColor="#000"
I'm new in Android studio and I'm trying to make two activities in my application but it don't works.
I don't know what I'm doing wrong, I think it's about the first options I put in my intent.
I'm new and I would like a simple solution or if you can explain me what I have to do it will be fine :)
This is my first activity (MainActivity):
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button mPasserelle = null;
public final static String AGE = "com.myapplis.multiactivite.AGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPasserelle = (Button) findViewById(R.id.passerelle);
mPasserelle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent secondeActivite = new Intent(MainActivity.this,IntentExample.class);
secondeActivite.putExtra(AGE,24);
startActivity(secondeActivite);
}
});
}
}
The second activity(IntentExample) :
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class IntentExample extends Activity{
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.seconde_activite);
Intent i = getIntent();
int age = i.getIntExtra(MainActivity.AGE,0);
TextView resultat= (TextView)findViewById(R.id.resultat);
resultat.setText("Le résultat est : "+age);
}
}
This is my first layout (activity_main), just a simple button to push to get the second 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.dunomade.multiactivite.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/passerelle"/>
</LinearLayout>
And now this is my second layout(seconde_activite), just a simple text to show me I'm on the second activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/resultat"
android:text="" />
</LinearLayout>
And to finish, this is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapplis.multiactivite">
<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>
<activity android:name=".IntentExample"
android:label="seconde acivite">
</activity>
</application>
</manifest>
When I'm running the app, MainActivity is good, but when I try to click on the button the AVD show me "Have you declared this activity in your AndroidManifest ?". I declared it on my manifest but I think the problem is in my MainActivity.
Please help me, I think for you it's really simple but I can't solve it, I tryed many way but I already got the same error.
Thank's for read and for answer =)
I advise that you use the name of package before the name of your activity, like this (some devices need this, like Moto G) :
<activity android:name="your.package.IntentExample "></activity>
And instead use:
public class IntentExample extends Activity
use:
public class IntentExample extends AppCompatActivity
My application is stopped when executed. I'm starting to program for android, just put a background and buttons, but it seems that I have problems creating the manifest. Before this project had many problems creating a new eclipse I put an activity together with the library and I started appcontainer_v7 errenter code hereored. To use the SDK 19 I decided to do everything manually.
CLASS:
package com.progra.cubebreaker;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class Menu extends Activity implements OnClickListener{
Button Jugar, Puntuaciones, Instrucciones;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
Jugar.findViewById(R.id.btJugar);
Puntuaciones.findViewById(R.id.btInstrucciones);
Instrucciones.findViewById(R.id.btInstrucciones);
Jugar.setOnClickListener(this);
Puntuaciones.setOnClickListener(this);
Instrucciones.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btJugar:
break;
case R.id.btPuntuaciones:
Toast text = Toast.makeText(this, "Pendiente...", Toast.LENGTH_SHORT);
text.show();
break;
case R.id.btInstrucciones:
Toast text1 = Toast.makeText(this, "Pendiente...", Toast.LENGTH_SHORT);
text1.show();
break;
}
}
}
LAYOUT:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/fondo1" >
<Button
android:id="#+id/btInstrucciones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/btPuntuaciones"
android:layout_marginBottom="89dp"
android:text="#string/instrucciones"
android:textSize="40dp"
android:textStyle="italic|normal|bold" />
<Button
android:id="#+id/btPuntuaciones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btInstrucciones"
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp"
android:text="#string/puntuaciones"
android:textSize="40dp"
android:textStyle="italic|normal|bold" />
<Button
android:id="#+id/btJugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btPuntuaciones"
android:layout_centerHorizontal="true"
android:layout_marginBottom="66dp"
android:text="#string/jugar"
android:textColorHint="#android:color/background_dark"
android:textSize="40dp"
android:textStyle="italic|normal|bold" />
</RelativeLayout>
MANIFEST:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.progra.cubebreaker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Menu"
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>
You are not mapping the layout objects to java class objects thats y ur application is crashing.
You need to map the java button by converting id of button or any other attribute to (Button) etc.
Modify your code :
Jugar = (Button) findViewById(R.id.btInstrucciones);
Puntuaciones= (Button) findViewById(R.id.btPuntuaciones);
Instrucciones = (Button) findViewById(R.id.btInstrucciones);
Hope that helps.
just replace this code,
Jugar.findViewById(R.id.btJugar);
Puntuaciones.findViewById(R.id.btInstrucciones);
Instrucciones.findViewById(R.id.btInstrucciones);
by
Jugar = (Button) findViewById(R.id.btJugar);
Puntuaciones = (Button) findViewById(R.id.btPuntuaciones);
Instrucciones = (Button) findViewById(R.id.btInstrucciones);
Your application is crashing as you are not initializing the widgets in your code.
Here is the error:
Jugar.findViewById(R.id.btJugar);
Puntuaciones.findViewById(R.id.btInstrucciones);
Instrucciones.findViewById(R.id.btInstrucciones);
Change it to:
Jugar = (Button) findViewById(R.id.btJugar);
Puntuaciones = (Button) findViewById(R.id.btPuntuaciones);
Instrucciones = (Button) findViewById(R.id.btInstrucciones);
I just wanted to click on a button in the MainActivity. After I clicked on this button a new activity appears. In this activity is also a button and when I click on this button a text appears. My Problem now is, that the text doesn't appear, when I click on the button. My code for clicking on a button so that a text appears is actually working. But not if I use it in a new Activity/Layout/ page. So there must be s.th. wrong with the Connection between the first and the second activity?!
MainActivity.java:
package com.example.xxx;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#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;}
{}
public void page2 (View view){
setContentView(R.layout.pagetwo);
}}
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" >
<Button
android:id="#+id/BtnKlick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="178dp"
android:text="Button"
android:onClick="page2"/>
</RelativeLayout>
Pagetwo.java:
package com.example.xxx;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Pagetwo extends Activity implements OnClickListener {
public Button btn1;
public TextView tw1;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.pagetwo);
btn1 = (Button) findViewById(R.id.BtnKlick);
tw1 = (TextView) findViewById(R.id.Text);
btn1.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
tw1.setText("Hallo");
}}
pagetwo.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/BtnKlick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Klick" />
<TextView
android:id="#+id/Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="87dp" />
</RelativeLayout>
AndroidManifest.xml:
<?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="18" />
<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>
</application>
</manifest>
Update
All you seem to be doing is swapping your layouts within PageOne activity.
Change
public void page2 (View view){
setContentView(R.layout.pagetwo);
}
to
public void page2 (View view){
Intent i = new Intent(this, Pagetwo.class);
startActivity(i);
}
This will actually launch your pagetwo activity rather than just swapping layouts within pageone activity
Make that change and all should be good. You will most likely have to add some imports, at least for the intent class
Also Activities must be registered in the manifest. To add the activity to your manifest check the code below
<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="Pagetwo"
android:label="#string/app_name" >
</activity>
</application>
Change the label to something more appropriate than app name once you have it working
End update
Try renaming your xml view id's to meet coding standards by using all lower case letters and separating words with underscores. The Android platform may well be getting confused as Text is a reserved word.
so
<TextView
android:id="#+id/Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="71dp"
android:textSize="70sp" />
becomes
<TextView
android:id="#+id/tv_hallo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="71dp"
android:textSize="70sp" />
and your code becomes
...
public TextView tw;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.eclipse);
btn = (Button) findViewById(R.id.BtnKlick);
tw = (TextView) findViewById(R.id.tv_hallo);
btn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
tw.setText("Hallo");
}
...
Not sure if this is going to have much of an effect but it is just possible android is getting the word Text confused
Also check your logcat output to see if there are any errors.
Update:
I have spent more than 2 hours to google, but I can't find the answer. I've add a main.java the handle the activity send from the Login Activity. Now the file tree looks like:
But still got error
E/AndroidRuntime(1282): android.content.ActivityNotFoundException: No
Activity found to handle Intent {
act=com.goodboy.loginIntent.action.main
cat=[android.intent.category.DEFAULT] (has extras) }
I know this question is simple, I am new to android, any help would be appreciated:)
Android allows for Intents that have specific recipients(the Activity or Service) as well as Intents that are broadcast throughout the system to any components that may be listening.
I want to make a PoC(Proof of Concept) that if we do not set setClassName, others can listen your private message.
This PoC is simple, suppose there is Login Activity for App Goodboy, when a user put his username and password in the login activity, and click the login button, the evil activity from App Badboy steal the this message.
However, failed:(
When I click the login button, failed:
And the evil intent got nothing:
The java source code of Login Activity
package com.goodboy.loginIntent;
import com.goodboy.loginIntent.R;
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.EditText;
public class GoodloginActivity extends Activity {
private EditText et_user;
private EditText et_pwd;
private Button btn_login;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
et_user = (EditText) findViewById(R.id.et_user);
et_pwd = (EditText) findViewById(R.id.et_pwd);
btn_login = (Button) findViewById(R.id.btn_login);
btn_login.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Intent m_intent = new Intent();
m_intent.putExtra("username", et_user.getText().toString());
m_intent.putExtra("password", et_pwd.getText().toString());
m_intent.setAction("com.goodboy.loginIntent.action.main");
m_intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(m_intent);
}
});
}
}
The source code of main.java
package com.goodboy.loginIntent;
import android.app.Activity;
import android.os.Bundle;
import com.goodboy.loginIntent.R;
public class main extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
The login layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/et_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/et_pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="#+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
The java source code of evil activity:
package com.badboy.stealIntent;
import com.badboy.stealIntent.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class BadIntentActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(getBaseContext(),
"username: "+this.getIntent().getStringExtra("username")+
"\npassword: "+this.getIntent().getStringExtra("password"),
Toast.LENGTH_SHORT).show();
}
}
Thanks #David Wasser, the manifest of login app(update):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.goodboy.loginIntent"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".GoodloginActivity"
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=".main"
android:label="#string/main" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The manifest of the badIntent:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.badboy.stealIntent"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".BadIntentActivity"
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>
You should take a look at Intent Intercept, an application aimed for developer which, as the name says, intercept any "public" Intent, allowing you to browse the intent setup and data. Intent Intercept is Open source, you can browse the code on GitHub
As for your problem, check that the BadBoy application is registered for the action you're using. Also, take a look at the stacktrace in logcat on goodlogin to see where the activity crashes.
You are probably getting an ActivityNotFoundException when you call startActivity() in GoodloginActivity because there is no Activity known to the system that responds to:
ACTION = "com.goodboy.loginIntent.action.main" and
CATEGORY = CATEGORY_DEFAULT
Have a look at your logcat output.