我试图从application2的主要活动中调用application1的activity2来触摸提交功能的提交按钮,但是我收到了这个错误:
android.content.ActivityNotFoundException:找不到要处理的Activity 意图{act = activity2.application1(有附加内容)}
我在application2之前运行application1,以便application2可以从application1找到activity2。
Application2 MainActivity.java
package com.example.application2;
import com.example.application2.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;
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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void submit(View v){
String s = "activity2.application1";
Intent intent = new Intent(s);
intent.putExtra("name", ((EditText)findViewById(R.id.editText1)).getText().toString());
intent.putExtra("about", ((EditText)findViewById(R.id.editText2)).getText().toString());
intent.putExtra("age", ((Spinner)findViewById(R.id.spinner1)).getSelectedItem().toString());
startActivity(intent);
}
}
Application1 activity2.java
package com.example.application1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class activity2 extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
Intent intent = getIntent();
TextView t1 = (TextView) findViewById(R.id.textView4);
t1.setText(intent.getStringExtra("name"));
TextView t2 = (TextView) findViewById(R.id.textView5);
t2.setText(intent.getStringExtra("age"));
TextView t3 = (TextView) findViewById(R.id.textView7);
t3.setText(intent.getStringExtra("about"));
}
}
Application1 AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.application1"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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" />
</intent-filter>
</activity>
<activity android:name=".activity2">
<intent-filter >
<action android:name="activity2.application1">
<category android:name="android.intent.category.DEFAULT"/>
</action>
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:0)
清单文件中缺少活动1。在清单文件中添加活动声明。
清单的内部应用程序标记,您可以添加新的活动,如:
<activity android:name=".newActivity"/>