2012-02-08 49 views
0

页面底部的这个意图只是说它无法启动事件。我试图用这个意图开始每一个其他的活动,它只是不起作用,而在我的主要活动中启动任何东西的意图工作得很好......无论如何,任何反馈意见。为什么我的意图关闭应用程序?

package com.chich; 

import android.app.Activity; 

import android.content.BroadcastReceiver; 
import android.content.ComponentName; 
import android.content.Context; 
import android.content.Intent; 
import android.content.IntentFilter; 
import android.content.pm.PackageManager; 
import android.os.Bundle; 
import android.view.Gravity; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.ImageView; 
import android.widget.Toast; 

public class second_activity extends Activity 
{ 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main2); 
    getWindow().setWindowAnimations(0); 


    Toast toast=Toast.makeText(this, "Your incoming texts and calls are now being blocked.", 2000); 
    toast.setGravity(Gravity.TOP, -30, 50); 
    toast.show(); 


    ImageView Image2 = (ImageView) findViewById(R.id.Image2); 
    Image2.setOnClickListener(new OnClickListener() 
    { 
     @Override 
     public void onClick(View Image2) 
     {  

      Intent intent = new Intent(second_activity.this, third_activity.class);    
      startActivity(intent); 
     }  

    }); 
} 

} 

清单文件:

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

<uses-permission android:name="android.permission.SEND_SMS"> 
</uses-permission> 
<uses-permission android:name="android.permission.RECEIVE_SMS"> 
</uses-permission> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <activity 
     android:name=".chich_activity" 
     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=".second_activity" 
       android:label="@string/app_name"> 
       <intent-filter> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
       </activity> 
       <activity android:name=".third_activity" 
       android:label="@string/app_name"> 
       <intent-filter> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
       </activity> 

    <receiver android:name=".SmsReceiver"> 
     <intent-filter android:priority="9999999" > 
      <action android:name = "android.provider.Telephony.SMS_RECEIVED" /> 
     </intent-filter> 
    </receiver> 
</application> 
</manifest> 

我不知道这意味着什么,但这里是我的logcat信息:3月2日至8日:11:00.062:d/UnlockClock(2500):GMT_update mRightNow。 getTime()。getID()== America/Los_Angeles 02-08 03:11:00.077:D/UnlockClock(2500):GMT_update current == America/Los_Angeles,TimeZone.getTimeZone(current).getID()== America/Los_Angeles 02-08 03:11:05.319:D/dalvikvm(17812):GC_EXPLICIT在151ms中释放了6871个对象/ 411088个字节02-08 03:11:07.058:I/3gw.Service(3071):移动网络已连接 - 02-08 03:11:07.527:D/dalvikvm(2500):GC_FOR_MALLOC释放39720个对象/ 20 83360字节在94ms 02-08 03:11:14.194:D/dalvikvm(16583):GC_EXPLICIT释放413ms中的413个对象/ 21640字节02-08 03:11:19.179:D/dalvikvm(18220):GC_EXPLICIT释放了168个对象/ 9000 bytes in 124ms 02-08 03:11:27.089:D/dalvikvm(17515):GC_EXPLICIT在221ms中释放了3个对象/ 72个字节02-08 03:11:32.269:D/dalvikvm(2664):GC_EXPLICIT释放了579个对象/ 35824个字节239ms 3月2日至8日:11:39.866:d/dalvikvm(16088):GC_EXPLICIT释放854个物体/ 26864字节186ms

回答

0

我想明白了,该解决方案实际上并未在本页面给出的代码中。

ComponentName locationReceiver = new ComponentName(second_activity.this, SmsReceiver.class); 
      PackageManager pm = getPackageManager(); 
      pm.setComponentEnabledSetting(locationReceiver,  PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); 

包管理器默认设置为在应用程序运行后终止它。您必须在最后使用“PackageManager.DONT_KILL_APP”命令它。虽然有些时候它只是有时会杀死应用程序,但很难真正找出错误的原因。谢谢大家的意见,我非常感谢。

0

更新你这样的代码 你不需要写每个意图过滤器活动。只需编辑您的AndroidManifest.xml像下面的`

Image2.setOnClickListener(new OnClickListener() 
{ 
    @Override 
    public void onClick(View v) 
    {  

     Intent intent = new Intent(second_activity.this,third_activity.class);    
     startActivity(intent); 
    }  

}); 

AndroidManifest.xml中

<application 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" > 
<activity 
    android:name=".chich_activity" 
    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=".second_activity" ></activity> 
<activity android:name=".third_activity"></activity> 

</application>` 
+0

我刚刚在third_activity中注释了启用和禁用接收函数,并且此意图工作得很好。这是什么使意图失败? – Christian 2012-02-08 20:46:11

0

据我知道,只有你的主要活动应该定义意图过滤器这样的。对于第二个和第三个活动,您只需要定义android:name。

+0

你是什么意思?我们不能在其他活动中使用意图? – OnkarDhane 2012-02-08 09:00:43

+0

对,我实际上改变了它的方式,它绝望地希望它能解决问题,但它没有... – Christian 2012-02-08 09:04:19

+0

嗯,你说得对,你究竟得到了什么错误? LogCat中的任何堆栈跟踪? – simon 2012-02-08 09:18:05

0

在eclipse中用xml编辑器重新添加活动。我想你是复制&从主要活动粘贴你的活动的东西。简单的活动(我认为second_activity和third_activity是简单的活动)通常不会有发射器。并且名字没有点。我想你已经改变了。

btw:你在使用eclipse吗? ctrl + shift + f是你的朋友。它将标准格式应用于文本(代码),使习惯了java标准“外观”的人们更容易阅读。

+0

雅试过,他们是..但谢谢你的Ctrl + Shift + F工具..我甚至不知道存在。 – Christian 2012-02-08 11:17:03

+0

你可以调试你的代码来检查Image2.setOnClickListener - onClick是否曾经被调用过吗?它看起来像你的清单是好的,因为你没有得到任何例外...... – eks 2012-02-08 16:06:30

+0

我会这样做,但我已经通过在onClick中放入一个使我的广播监听器(它中止广播)的方法进行检查,并且它工作正常。不幸的是它仍然关闭了应用程序。 – Christian 2012-02-08 18:15:41

相关问题