我的Android应用程序将包含三个用于此问题的活动。第一个是Main
,然后是FishActivity
,最后是AnthiasActivity
。我正在使用按钮来启动这些活动。我可以从FishAcivity
启动Main
,但是当我使用类似的代码时,我无法从AnthiasActivity
启动FishActivity
。应用程序关闭并声明"不幸的是,Reef Fish Guide已停止。我在eclipse中没有错误。
编辑:注意:当我删除启动意图" AnthiasActivity"来自" fishActivity",鱼活动运行正常(只是无法启动下一个活动)。但是,当我将代码添加到Fish Activity中以启动AnthiasActivity时," FishActivity"根本不会发动。
主:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button fishButton = (Button) findViewById(R.id.fish);
fishButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, FishActivity.class);
startActivity(intent);
}
});
Button coralButton = (Button) findViewById(R.id.coral);
coralButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, CoralActivity.class);
startActivity(intent);
}
});
Button invertsButton = (Button) findViewById(R.id.inverts);
invertsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent (MainActivity.this, InvertsActivity.class);
startActivity(intent);
}
});
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@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);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
FishActivity
public class FishActivity extends MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fish);
Button anthiasButton1 = (Button) findViewById(R.id.anthiasButton);
anthiasButton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent2 = new Intent(FishActivity.this, AnthiasActivity.class);
startActivity(intent2);
}
});
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
protected Context getActivity(FishActivity fishActivity) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.fish, 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);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_fish, container,
false);
return rootView;
}
}
}
AnthiasActivity
public class AnthiasActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_anthias);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.anthias, 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);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_anthias,
container, false);
return rootView;
}
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kdc.reeffishguide"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.kdc.reeffishguide.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="com.kdc.reeffishguide.FishActivity"
android:label="@string/title_activity_fish" >
</activity>
<activity
android:name="com.kdc.reeffishguide.CoralActivity"
android:label="@string/title_activity_coral" >
</activity>
<activity
android:name="com.kdc.reeffishguide.InvertsActivity"
android:label="@string/title_activity_inverts" >
</activity>
<activity
android:name="com.kdc.reeffishguide.AnthiasActivity"
android:label="@string/title_activity_anthias" >
</activity>
</application>
</manifest>
编辑: logcat的
04-18 10:22:41.467: E/QcrilMsgTunnelSocket(11564): IOExceptionjava.io.IOException: No such file or directoryReason: No such file or directory
04-18 10:22:41.687: E/MP-Decision(2162): num online cores: 1 reqd : 2 available : 4 rq_depth:1.300000 hotplug_avg_load_dw: 67
04-18 10:22:41.687: E/MP-Decision(2162): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 total_time_up:0.000000
04-18 10:22:41.988: E/MP-Decision(2162): num online cores: 2 reqd : 1 available : 4 rq_depth:1.000000 hotplug_avg_load_dw: 22
04-18 10:22:41.988: E/MP-Decision(2162): DOWN cpu:1 core_idx:1 Ns:1.100000 Ts:190 total_time_down:190.000000
04-18 10:22:44.150: E/Watchdog(923): !@Sync 154
04-18 10:22:45.481: E/QcrilMsgTunnelSocket(11564): IOExceptionjava.io.IOException: No such file or directoryReason: No such file or directory
04-18 10:22:45.671: E/MP-Decision(2162): num online cores: 1 reqd : 2 available : 4 rq_depth:4.300000 hotplug_avg_load_dw: 25
04-18 10:22:45.671: E/MP-Decision(2162): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 total_time_up:145.000000
04-18 10:22:45.972: E/MP-Decision(2162): num online cores: 2 reqd : 1 available : 4 rq_depth:0.000000 hotplug_avg_load_dw: 17
04-18 10:22:45.972: E/MP-Decision(2162): DOWN cpu:1 core_idx:1 Ns:1.100000 Ts:190 total_time_down:195.000000
04-18 10:22:49.485: E/QcrilMsgTunnelSocket(11564): IOExceptionjava.io.IOException: No such file or directoryReason: No such file or directory
04-18 10:22:53.479: E/QcrilMsgTunnelSocket(11564): IOExceptionjava.io.IOException: No such file or directoryReason: No such file or directory
04-18 10:22:57.483: E/QcrilMsgTunnelSocket(11564): IOExceptionjava.io.IOException: No such file or directoryReason: No such file or directory
04-18 10:23:00.155: E/MP-Decision(2162): num online cores: 1 reqd : 2 available : 4 rq_depth:3.200000 hotplug_avg_load_dw: 29
04-18 10:23:00.155: E/MP-Decision(2162): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 total_time_up:145.000000
04-18 10:23:00.846: E/MP-Decision(2162): num online cores: 2 reqd : 1 available : 4 rq_depth:1.500000 hotplug_avg_load_dw: 11
04-18 10:23:00.846: E/MP-Decision(2162): DOWN cpu:1 core_idx:1 Ns:1.100000 Ts:190 total_time_down:0.000000
04-18 10:23:01.487: E/QcrilMsgTunnelSocket(11564): IOExceptionjava.io.IOException: No such file or directoryReason: No such file or directory
04-18 10:23:05.481: E/QcrilMsgTunnelSocket(11564): IOExceptionjava.io.IOException: No such file or directoryReason: No such file or directory
04-18 10:23:08.163: E/SmartFaceManager(923): checkForSmartStay S
04-18 10:23:08.163: E/SmartFaceService(923): setValue, key: smart-stay-framecount-reset value:
04-18 10:23:08.163: E/SmartFaceService(923): register:4668116
04-18 10:23:08.173: E/SmartFaceService.Client(923): New SmartFaceService.Client, service type: 100 pid: 923
04-18 10:23:08.193: E/CameraController(923): Wait for 1
04-18 10:23:08.193: E/CameraController(923): handleMessage: { what=1 when=-3ms arg1=4 }
04-18 10:23:08.213: E/SecCamera-JNI-Java(923): SecCamera.open()
04-18 10:23:08.213: E/CameraController(923): open() as 100
04-18 10:23:08.223: E/SecCamera-JNI-Java(923): SecCamera()
04-18 10:23:08.223: E/CameraService(370): system_server
04-18 10:23:08.233: E/CameraService(370): CameraService::connect before lock (pid 923, org id 11)
04-18 10:23:08.233: E/CameraService(370): orgID: 3 checkingID: 0 seems GOOD
04-18 10:23:08.233: E/CameraService(370): orgID: 3 checkingID: 1 seems GOOD
04-18 10:23:08.233: E/CameraService(370): orgID: 3 checkingID: 2 seems GOOD
04-18 10:23:08.233: E/CameraService(370): orgID: 3 checkingID: 3 seems GOOD
04-18 10:23:08.233: E/CameraService(370): orgID: 3 checkingID: 4 seems GOOD
04-18 10:23:08.233: E/QualcommCamera(370): Qint android::get_camera_info(int, camera_info*): E
04-18 10:23:08.313: E/SecCameraCoreManager(370): !@ cam: CaMeRa(3)
04-18 10:23:08.313: E/SecCameraCoreManager(370): initialize1
04-18 10:23:08.313: E/QualcommCamera(370): int android::camera_device_open(const hw_module_t*, char const*, hw_device_t**): start : 1
04-18 10:23:08.313: E/mm-camera-intf(370): mm_camera_native_control : mode(46), value1(0), value2(0), value3(1)
04-18 10:23:08.323: E/mm-camera(401): mctl_store_curr_target Current target is 0
04-18 10:23:08.323: E/mm-camera(401): camera_plugin_client_open: plugin client open exit, rc = 0
04-18 10:23:08.323: E/mm-camera-intf(370): mm_camera_open: opened, break out while loop