我已经看过关于这个主题的所有帖子,但遗憾的是,因为我是一个初学者,我只是无法将这些帖子的任何解决方案与我的解决方案联系起来。 因此,我将我的代码放在下面,以便您可以为我提供定制的回复..
我正在尝试在我的手机上启动一个应用程序。提供了一个按钮,按下时应该执行启动活动
我附上以下文件以供参考
package com.mycompany.myapp3;
import android.app.*;
import android.os.*;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity
{
Button button;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnbutton();
}
public void addListenerOnbutton() {
button=(Button)findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0){
Intent intent = new Intent("com.xyz.speed");
startActivity(intent);
}
});
}
}
接下来是manifestfile
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp3" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:resizeableActivity = "true">
<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>
</application>
</manifest>
05-18 19:02:41.987 9919 9919 E SELinux [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
05-18 19:02:41.987 9919 9919 I art Late-enabling -Xcheck:jni
05-18 19:02:42.007 9919 9919 D TimaKeyStoreProvider in addTimaSignatureService
05-18 19:02:42.017 9919 9919 D TimaKeyStoreProvider TimaSignature is unavailable
05-18 19:02:42.017 9919 9919 D ActivityThread Added TimaKesytore provider
05-18 19:02:42.057 9919 9919 I InjectionManager Inside getClassLibPath + mLibMap{0=, 1=}
05-18 19:02:42.057 9919 9919 W ResourcesManager getTopLevelResources: com.mycompany.myapp3 for user 0
05-18 19:02:42.067 9919 9919 I InjectionManager Inside getClassLibPath caller
05-18 19:02:42.087 9919 9919 D InjectionManager InjectionManager
05-18 19:02:42.087 9919 9919 D InjectionManager fillFeatureStoreMap com.mycompany.myapp3
05-18 19:02:42.087 9919 9919 I InjectionManager Constructor com.mycompany.myapp3, Feature store :{}
05-18 19:02:42.087 9919 9919 I InjectionManager featureStore :{}
05-18 19:02:42.117 9919 9919 W ResourcesManager getTopLevelResources: com.mycompany.myapp3 for user 0
05-18 19:02:42.127 9919 9919 D DisplayManager DisplayManager()
05-18 19:02:42.127 9919 9919 W ResourcesManager getTopLevelResources: com.mycompany.myapp3 for user 0
05-18 19:02:42.157 9919 9919 D PhoneWindow *FMB* installDecor mIsFloating : false
05-18 19:02:42.157 9919 9919 D PhoneWindow *FMB* installDecor flags : -2139029248
05-18 19:02:42.167 9919 9919 D Activity performCreate Call Injection manager
05-18 19:02:42.177 9919 9919 I InjectionManager dispatchOnViewCreated > Target : com.mycompany.myapp3.MainActivity isFragment :false
05-18 19:02:42.197 9919 9948 D OpenGLRenderer Use EGL_SWAP_BEHAVIOR_PRESERVED: true
05-18 19:02:42.217 9919 9919 D PhoneWindow *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
05-18 19:02:42.217 9919 9919 D PhoneWindow *FMB* isFloatingMenuEnabled return false
05-18 19:02:42.257 9919 9948 D libEGL loaded /vendor/lib/egl/libGLES_mali.so
05-18 19:02:42.297 9919 9948 I OpenGLRenderer Initialized EGL, version 1.4
05-18 19:02:42.307 9919 9948 D OpenGLRenderer Enabling debug mode 0
05-18 19:02:42.307 9919 9948 D mali_winsys new_window_surface returns 0x3000, [720x1280]-format:1
05-18 19:02:42.317 9919 9919 I InjectionManager dispatchCreateOptionsMenu :com.mycompany.myapp3.MainActivity
05-18 19:02:42.317 9919 9919 I InjectionManager dispatchPrepareOptionsMenu :com.mycompany.myapp3.MainActivity
05-18 19:02:42.507 9919 9919 I Timeline Timeline: Activity_idle id: android.os.BinderProxy@49f2b0d time:38707264
05-18 19:02:43.557 9919 9919 D ViewRootImpl ViewPostImeInputStage ACTION_DOWN
05-18 19:02:43.667 9919 9919 D Instrumentation checkStartActivityResult :Intent { act=com.xyz.speed }
05-18 19:02:43.667 9919 9919 D Instrumentation checkStartActivityResult inent is instance of inent:
05-18 19:02:43.677 9919 9919 D AndroidRuntime Shutting down VM
05-18 19:02:43.677 9919 9919 E AndroidRuntime FATAL EXCEPTION: main
05-18 19:02:43.677 9919 9919 E AndroidRuntime Process: com.mycompany.myapp3, PID: 9919
05-18 19:02:43.677 9919 9919 E AndroidRuntime android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.rma.myspeed }
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1815)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.app.Instrumentation.execStartActivity(Instrumentation.java:1513)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.app.Activity.startActivityForResult(Activity.java:3933)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.app.Activity.startActivityForResult(Activity.java:3881)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.app.Activity.startActivity(Activity.java:4204)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.app.Activity.startActivity(Activity.java:4172)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at com.mycompany.myapp3.MainActivity$100000000.onClick(MainActivity.java:36)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.view.View.performClick(View.java:5076)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.view.View$PerformClick.run(View.java:20279)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.os.Handler.handleCallback(Handler.java:739)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:95)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.os.Looper.loop(Looper.java:135)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:5930)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at java.lang.reflect.Method.invoke(Native Method)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at java.lang.reflect.Method.invoke(Method.java:372)
05-18 19:02:43.677 9919 9919 E AndroidRuntime at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
答案 0 :(得分:0)
首先,您必须在AndroidManifest.xml
文件中注册要在应用中使用的每个活动。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
....>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
....
<activity android:name="com.example.ExampleActivity"/>
注册后,您可以执行它。
开始活动:
Intent intent = new Intent(this, ExampleActivity.class);
startActivity(intent);