2
    package com.tchotchke.weatherpaper;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.tchotchke.weatherpaper.util.SystemUiHider;


public class FullscreenActivity extends Activity{

    OnClickListener buttons;

    private static final boolean AUTO_HIDE = true;
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
    private static final boolean TOGGLE_ON_CLICK = true;
    private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
    private SystemUiHider mSystemUiHider;
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);
        final View controlsView = findViewById(R.id.fullscreen_content_controls);
        final View contentView = findViewById(R.id.fullscreen_content);

        Button objects_button = (Button)findViewById(R.id.objects_button);

        buttons = new OnClickListener(){
            @Override
            public void onClick(View v){
                Intent intent = new Intent("com.tchotchke.MYOBJECTS");
                startActivity(intent);
            }
        };
        objects_button.setOnClickListener(buttons);

        mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
        mSystemUiHider.setup();
        mSystemUiHider.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener`() {`
                    // Cached values.
                    int mControlsHeight;
                    int mShortAnimTime;

                    @Override
                    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
                    public void onVisibilityChange(boolean visible) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                            // If the ViewPropertyAnimator API is available
                            // (Honeycomb MR2 and later), use it to animate the
                            // in-layout UI controls at the bottom of the
                            // screen.
                            if (mControlsHeight == 0) {
                                mControlsHeight = controlsView.getHeight();
                            }
                            if (mShortAnimTime == 0) {
                                mShortAnimTime = getResources().getInteger(
                                        android.R.integer.config_shortAnimTime);
                            }
                            controlsView.animate()
                                    .translationY(visible ? 0 : mControlsHeight)
                                    .setDuration(mShortAnimTime);
                        } else {
                            // If the ViewPropertyAnimator APIs aren't
                            // available, simply show or hide the in-layout UI
                            // controls.
                            controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
                        }

                        if (visible && AUTO_HIDE) {
                            // Schedule a hide().
                            delayedHide(AUTO_HIDE_DELAY_MILLIS);
                        }
                    }
                });

        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TOGGLE_ON_CLICK) {
                    mSystemUiHider.toggle();
                } else {
                    mSystemUiHider.show();
                } }});   }



    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        delayedHide(100);
    }

    View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
            return false;
        }
    };

    Handler mHideHandler = new Handler();
    Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            mSystemUiHider.hide();
        }
    };

    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }



    }

我的 logcat 看起来像这样(在单击按钮之前没有错误)

- 03-21 15:57:30.871: D/gralloc_goldfish(1034): Emulator without GPU emulation detected.

-03-21 15:57:31.812: I/Choreographer(1034): Skipped 107 frames!  The application may be doing too much work on its main thread.

-03-21 15:57:32.531: D/dalvikvm(1034): GC_CONCURRENT freed 185K, 11% free 2580K/2896K, paused 3ms+3ms, total 197ms

-03-21 15:57:51.971: I/Choreographer(1034): Skipped 32 frames!  The application may be doing too much work on its main thread.

-03-21 15:57:58.684: D/AndroidRuntime(1034): Shutting down VM

-03-21 15:57:58.692: W/dalvikvm(1034): threadid=1: thread exiting with uncaught exception (group=0x40a71930)

-03-21 15:57:58.702: E/AndroidRuntime(1034): FATAL EXCEPTION: main

-03-21 15:57:58.702: E/AndroidRuntime(1034): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.tchotchke.MYOBJECTS }

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.app.Activity.startActivityForResult(Activity.java:3370)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.app.Activity.startActivityForResult(Activity.java:3331)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.app.Activity.startActivity(Activity.java:3566)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.app.Activity.startActivity(Activity.java:3534)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at com.tchotchke.weatherpaper.FullscreenActivity$3.onClick(FullscreenActivity.java:40)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.view.View.performClick(View.java:4204)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.view.View$PerformClick.run(View.java:17355)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.os.Handler.handleCallback(Handler.java:725)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.os.Handler.dispatchMessage(Handler.java:92)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.os.Looper.loop(Looper.java:137)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at android.app.ActivityThread.main(ActivityThread.java:5041)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at java.lang.reflect.Method.invokeNative(Native Method)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at java.lang.reflect.Method.invoke(Method.java:511)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)

-03-21 15:57:58.702: E/AndroidRuntime(1034):    at dalvik.system.NativeStart.main(Native Method)

这是我的清单,抱歉我把它漏掉了:

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="com.tchotchke.weatherpaper.FullscreenActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.tchotchke.weatherpaper.MyObjects"
            android:label="@string/dummy_button">
            <action android:name="android.intent.action.MYOBJECTS"/>
        </activity>


    </application>

</manifest>

我对清单的工作方式不是很确定,但从我所看到的来看,它似乎是合法的

4

2 回答 2

4

它没有找到您的活动"com.tchotchke.MYOBJECTS,您需要在清单中声明此活动。如果这是您项目中的一项活动,那么意图通常通过以下方式完成:

Intent intent = new Intent(YourCurrentClassName.this, MYOBJECTS.class);
startActivity(intent);

希望这可以帮助。

于 2013-03-21T16:14:45.957 回答
0
Intent intent = new Intent(this, MYOBJECTS.class);
intent.setAction("com.tchotchke.MYOBJECTS");
startActivity(intent);

你好朋友它可以通过上述方式完成

于 2013-03-21T16:39:59.220 回答