从另一个活动的按钮单击调用活动类失败

时间:2011-07-24 03:57:41

标签: android android-layout android-manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.org.EasyUpload"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".EasyUploadActivity"
                  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=".EasyUploadSendLink">
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="7"/>
    <uses-permission android:name="android.permission.INTERNET">
    </uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
    </uses-permission>
    <uses-permission android:name="android.permission.READ_PHONE_STATE">
    </uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
    </uses-permission>
    <uses-permission android:name="android.permission.INSTALL_PACKAGES">
    </uses-permission>
    <uses-permission android:name="android.permission.MOUNT_FORMAT_FILESYSTEMS">
    </uses-permission>
    <uses-permission android:name="android.permission.READ_OWNER_DATA">
    </uses-permission>
    <uses-permission android:name="android.permission.REBOOT">
    </uses-permission>
    <uses-permission android:name="android.permission.WRITE_OWNER_DATA">
    </uses-permission>
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS">
    </uses-permission>
    <uses-permission android:name="android.permission.WRITE_SETTINGS">
    </uses-permission>
</manifest>



public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final EditText linkLocation = (EditText)findViewById(R.id.linkLocation);
        final Button download = (Button)findViewById(R.id.download);
        final TextView message = (TextView)findViewById(R.id.message);
        final Button callDownloadLinkMethod = (Button)findViewById(R.id.callDownloadLinkMethod);

        callDownloadLinkMethod.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent callDownloadPage = new Intent(v.getContext(), EasyUploadSendLink.class);
                startActivityForResult(callDownloadPage, 0);
            }
        });




public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_upload);

        final AutoCompleteTextView username = (AutoCompleteTextView)findViewById(R.id.username);
        final AutoCompleteTextView downloadLink = (AutoCompleteTextView)findViewById(R.id.downloadLink);
        final Button download = (Button)findViewById(R.id.download);

        download.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                String url = "some random url";
                Intent callHttp = new Intent(Intent.ACTION_VIEW);
                callHttp.setData(Uri.parse(url));
                startActivity(callHttp);
            }
        });
    }
}

堆栈跟踪

07-24 01:35:28.660: DEBUG/AndroidRuntime(247): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
07-24 01:35:28.680: DEBUG/AndroidRuntime(247): CheckJNI is ON
07-24 01:35:29.241: DEBUG/AndroidRuntime(247): --- registering native functions ---
07-24 01:35:30.181: DEBUG/ddm-heap(247): Got feature list request
07-24 01:35:31.484: WARN/ResourceType(61): Resources don't contain package for resource number 0x7f0700e5
07-24 01:35:31.507: WARN/ResourceType(61): Resources don't contain package for resource number 0x7f020031
07-24 01:35:31.530: WARN/ResourceType(61): Resources don't contain package for resource number 0x7f020030
07-24 01:35:31.530: WARN/ResourceType(61): Resources don't contain package for resource number 0x7f050000
07-24 01:35:31.831: WARN/ResourceType(61): Resources don't contain package for resource number 0x7f060000
07-24 01:35:31.892: WARN/ResourceType(61): Resources don't contain package for resource number 0x7f060001
07-24 01:35:34.071: DEBUG/dalvikvm(61): GC freed 2844 objects / 154080 bytes in 576ms
07-24 01:35:35.311: INFO/ActivityManager(61): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.org.EasyUpload/.EasyUploadActivity }
07-24 01:35:35.411: DEBUG/AndroidRuntime(247): Shutting down VM
07-24 01:35:35.411: DEBUG/dalvikvm(247): DestroyJavaVM waiting for non-daemon threads to exit
07-24 01:35:35.491: DEBUG/dalvikvm(247): DestroyJavaVM shutting VM down
07-24 01:35:35.491: DEBUG/dalvikvm(247): HeapWorker thread shutting down
07-24 01:35:35.502: DEBUG/dalvikvm(247): HeapWorker thread has shut down
07-24 01:35:35.502: DEBUG/jdwp(247): JDWP shutting down net...
07-24 01:35:35.502: DEBUG/jdwp(247): Got wake-up signal, bailing out of select
07-24 01:35:35.502: INFO/dalvikvm(247): Debugger has detached; object registry had 1 entries
07-24 01:35:35.511: DEBUG/dalvikvm(247): VM cleaning up
07-24 01:35:35.732: DEBUG/dalvikvm(247): LinearAlloc 0x0 used 639500 of 5242880 (12%)
07-24 01:35:35.901: WARN/ActivityManager(61): Activity pause timeout for HistoryRecord{44d86d78 com.android.launcher/.Launcher}
07-24 01:35:36.281: INFO/ActivityManager(61): Start proc com.org.EasyUpload for activity com.org.EasyUpload/.EasyUploadActivity: pid=254 uid=10028 gids={3003, 1015}
07-24 01:35:37.263: DEBUG/ddm-heap(254): Got feature list request
07-24 01:35:40.371: INFO/ActivityManager(61): Displayed activity com.android.launcher/.Launcher: 861216 ms (total 4460 ms)
07-24 01:35:40.681: DEBUG/dalvikvm(61): threadid=15: bogus mon 1+0>0; adjusting
07-24 01:35:41.221: DEBUG/dalvikvm(226): GC freed 525 objects / 45888 bytes in 10 sec
07-24 01:35:45.990: DEBUG/dalvikvm(115): GC freed 2263 objects / 132320 bytes in 538ms
07-24 01:37:03.621: DEBUG/KeyguardViewMediator(61): pokeWakelock(5000)
07-24 01:37:03.721: DEBUG/KeyguardViewMediator(61): pokeWakelock(5000)
07-24 01:37:03.822: DEBUG/KeyguardViewMediator(61): pokeWakelock(5000)
07-24 01:37:03.981: DEBUG/KeyguardViewMediator(61): pokeWakelock(5000)

当我尝试从第一个活动中调用第二个活动时,单击一个按钮,它会发出异常并强制关闭活动。我是android开发的新手,这就是为什么我粘贴了AndroidManifest.xml和Activity类的相关部分。如果我做错了什么或错过了什么,请指出。

1 个答案:

答案 0 :(得分:2)

YourClass.this.startActivity(callHttp);将完成工作

编辑: 为您的第二个活动添加类别

            <intent-filter>                    
                <category android:name="android.intent.category.VIEW" />
            </intent-filter>

由于您的logcat未完成。我猜:

 Intent callDownloadPage = new Intent(YOURCLASS.this, EasyUploadSendLink.class);
            startActivityForResult(callDownloadPage, 0);

确保您的清单中有<activity表示您开始的每个意图。这很重要。