Android无法启动活动

时间:2012-06-09 10:24:45

标签: android android-activity android-intent

所以我有这个活动:

public class settings_dock extends Activity {

    AlertDialog alert;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.settings); 


        //Weather settings
        ListView listView = (ListView) findViewById(R.id.settings);
        String[] values = new String[] { "Enable/Disable","Configure Item 1","Configure Item 2","Configure Item 3","Configure Item 4"};




        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, values);

            // Assign adapter to ListView
            listView.setAdapter(adapter);

        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
                if(position == 0)
                {

                    final CharSequence[] items = {"Enabled", "Disabled"};

                    AlertDialog.Builder builder = new AlertDialog.Builder(settings_dock.this);
                    builder.setTitle("The Dock is ....");



                    SharedPreferences dock = app.getContext().getSharedPreferences("dock",app.getContext().MODE_WORLD_READABLE);

                    builder.setSingleChoiceItems(items,dock.getInt("enabled_disabled",-1), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int item) {

                            SharedPreferences dock = app.getContext().getSharedPreferences("dock",app.getContext().MODE_WORLD_READABLE);
                             SharedPreferences.Editor prefsEditor = dock.edit();
                             prefsEditor.putInt("enabled_disabled",item);
                             prefsEditor.commit();
                             alert.dismiss();
                             if(item == 0)
                             {

                             }
                            if(item == 1)
                                {

                                }


                        }
                    });
                    alert = builder.create();
                    alert.show();
                }
                if(position == 1)
                {
                    Intent in=new Intent(settings_dock.this,set_dock.class);
                    in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    in.putExtra("dock_location",1);

                }
                if(position == 2)
                {
                    Intent in=new Intent(settings_dock.this,set_dock.class);
                    in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    in.putExtra("dock_location",2);
                }
                if(position == 3)
                {
                    Intent in=new Intent(settings_dock.this,set_dock.class);
                    in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    in.putExtra("dock_location",3);
                }
                if(position == 4)
                {
                    Intent in=new Intent(settings_dock.this,set_dock.class);
                    in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    in.putExtra("dock_location",4);
                }


            }
        });
    }

}

我试图启动一个你可以看到的意图 但simplay没有任何事情发生在logcat中甚至没有错误 发布的意图在我的清单

中被提升

我现在真的很困惑:(

修改 清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.alexander.fuchs.lockscreen"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>


    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

        <activity
            android:name=".app"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:excludeFromRecents="true"
            android:clearTaskOnLaunch="true"> 
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name="boot">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </receiver>

        <service
        android:name="lockservice" 
        android:process=":lockscreen" 
        android:icon="@drawable/ic_launcher"
        android:label="Lockscreen">
        </service>

        <activity
            android:name=".weather_update"
            android:theme="@android:style/Theme.Translucent">

        </activity>
        <activity
            android:name=".restart_service"
            android:theme="@android:style/Theme.Translucent">

        </activity>
        <activity
            android:name=".settings">

        </activity>
        <activity
            android:name=".settings_weather">

        </activity>
        <activity
            android:name=".settings_general">

        </activity>
        <activity
            android:name=".settings_dock">

        </activity>
        <activity
            android:name=".settings_personalisation">

        </activity>
        <activity
            android:name=".set_dock"
            android:theme="@android:style/Theme.Dialog"
            android:screenOrientation="portrait">

        </activity>

    </application>

</manifest>

2 个答案:

答案 0 :(得分:2)

您尚未致电:

startActivity(in);

希望这有帮助。

答案 1 :(得分:0)

尝试在每个startActivity(in)语句中添加if。要开始活动,您需要调用startActivity(intent)方法。