Contenho as seguintes telas no projeto:
AboutScreen.java - about_screen.xml
CameraOverlayBooks.java - camera_overlay_books.xml
A tela “CameraOverlayBooks.java” na verdade é uma tela que é a camera ligada do celular do usuário.
Nela eu inseri um button para poder voltar a tela AboutScreen.java.
O que está acontecendo é o seguinte:
Inseri Intent na tela AboutScreen.java, porém nada acontece ao clicar no botão da tela CameraOverlayBooks. Nem mesmo uma mensagem de errro.
Segue os códigos abaixo:
- AboutScreen.java
package com.vuforia.samples.Books.ui.ActivityList;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import com.vuforia.samples.Books.R;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
public class AboutScreen extends Activity implements OnClickListener
{
private static final String LOGTAG = “AboutScreen”;
private Button mStartButton; private String mClassToLaunch; private String mClassToLaunchPackage; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.about_screen); Bundle extras = getIntent().getExtras(); mClassToLaunchPackage = getPackageName(); mClassToLaunch = mClassToLaunchPackage + "." + extras.getString("ACTIVITY_TO_LAUNCH");
mStartButton = (Button) findViewById(R.id.button_start); mStartButton.setOnClickListener(this);
} // Starts the chosen activity private void startARActivity() { Intent i = new Intent(); i.setClassName(mClassToLaunchPackage, mClassToLaunch); startActivity(i); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.button_start: startARActivity(); break; } }
}
- AboutScreen.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/white" android:name="AboutScreen">
<TextView android:id="@+id/about_text_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/blue_aliansce" android:gravity="center" android:layout_alignParentTop="true" android:fontFamily="sans-serif" android:textStyle="bold" android:textColor="@color/white" android:padding="@dimen/menu_title_padding" android:text="@string/menu_title" android:textSize="@dimen/menu_title" />
<Button android:id="@+id/button_start" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/green_aliansce" android:gravity="center_horizontal|center_vertical" android:textSize="@dimen/menu_title" android:textColor="@color/white" android:fontFamily="sans-serif" android:text="@string/button_start" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> </RelativeLayout>
-
CameraOverlayBooks.java
package com.vuforia.samples.Books.ui.ActivityList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.vuforia.samples.Books.R;public class CameraOverlayBooks extends Activity{
private Button BackButton; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.camera_overlay_books); Button BackButton = (Button) findViewById(R.id.button_back); BackButton.setOnClickListener(new View.OnClickListener(){ public void onClick(View view) { Intent trocarTela = new Intent(CameraOverlayBooks.this, AboutScreen.class); startActivity(trocarTela); } }); }
}
-
CameraOverlayBooks.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout android:id="@+id/loading_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@color/semi_transparent_black" android:padding="30dip" android:visibility="gone" > <ProgressBar style="@android:style/Widget.ProgressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> </RelativeLayout> <Button android:id="@+id/overlay_close_button" android:layout_width="50dp" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:background="@drawable/close_button_background" android:visibility="gone" /> <Button android:id="@+id/button_back" android:layout_width="50dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_below="@+id/loading_layout" android:layout_toEndOf="@+id/loading_layout" android:layout_toRightOf="@+id/loading_layout" android:background="@drawable/back_button_background" /> <TextView android:id="@+id/overlay_status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="70dp" android:background="@color/semi_transparent_black" android:gravity="center" android:paddingBottom="10dp" android:paddingLeft="30dp" android:paddingRight="30dp" android:paddingTop="10dp" android:text="@string/status_bar_scanning" android:textColor="@color/white" android:textSize="@dimen/overlay_status" android:visibility="gone" /> <ImageView android:id="@+id/scan_line" android:layout_width="match_parent" android:layout_height="50px" android:src="@drawable/scanline" android:scaleType="fitXY" android:visibility="gone"/>
-
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<!–
The application’s compatibility with one or more versions of the Android
platform.android:minSdkVersion = application's required minimum API level to run android:targetSdkVersion = application's targeted API level --> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" /> <uses-feature android:glEsVersion="0x00020000" /> <!-- The application requires a camera. NOTE: Any application that requests the CAMERA permission but does not declare any camera features with the <uses-feature> element will be assumed to use all camera features (auto-focus and flash). Thus, the application will not be compatible with devices that do not support all camera features. Please use <uses-feature> to declare only the camera features that your application does need. For instance, if you request the CAMERA permission, but you do not need auto-focus or flash, then declare only the android.hardware.camera feature. The other camera features that you do not request will no longer be assumed as required. --> <uses-feature android:name="android.hardware.camera" /> <!-- Add this permission to get access to the camera. --> <uses-permission android:name="android.permission.CAMERA" /> <!-- Add this permission to allow opening network sockets. --> <uses-permission android:name="android.permission.INTERNET" /> <!-- Add this permission to check which network access properties (e.g. active type: 3G/WiFi). --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- NOTE: The setting 'android:launchMode="singleTask"' makes sure that the activity can begin only one task and the device can hold only one instance of the activity at a time. However, it allows other activities to be part of its task (unlike the 'singleInstance' mode). It's at the root of the activity stack, but other activities (necessarily "standard" and "singleTop" activities) can be launched into the same task. If this attribute is not set, the default value 'standard' is used, which would allow the activity to be launched multiple times. --> <application android:allowBackup="true" android:description="@string/app_description" android:icon="@drawable/icon" android:label="@string/app_name" android:launchMode="singleTask" android:theme="@style/SampleAppsTheme"> <!-- NOTE: The values in 'android:configChanges' ensure that Android will not destroy and re-create the activity when the user flips the keyboard, changes the orientation of the device, or the actual or physical screen resolution changes, but calls the Activity's onConfigurationChanged() function instead. NOTE 2: In order to prevent automatic reactions to orientation changes in addition to setting proper values for 'android:configChanges', you also must explicitly specify the screen orientation used by the application, either by setting the attribute 'android:screenOrientation' or in code by calling Activity.setRequestedOrientation(). --> <!-- Splash Screen Activity --> <activity android:name=".ui.ActivityList.ActivitySplashScreen" android:configChanges="orientation|keyboardHidden" android:noHistory="true" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".ui.ActivityList.AboutScreen" android:configChanges="orientation|keyboardHidden" android:screenOrientation="portrait" /> <activity android:name=".ui.ActivityList.CameraOverlayBooks" android:configChanges="orientation|keyboardHidden" android:screenOrientation="portrait" /> <activity android:name=".app.Books.Books" android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize" android:launchMode="singleTask" android:theme="@style/SampleAppsTheme" /> </application>