Android studio button taking me to wrong activity - java

I'm relatively new to Android Studio, this is my 2nd project. I'm currently having an issue that just recently appeared when when I run my app, when I click on the create_account button on the main menu activity. Its sending me to my ViewlogActivity for some reason. And when I click on my Viewlogs button it does nothing. I double checked my intents and have both activities in my manifest file. Whats going on?
My Code:
Manifest File:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
s<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- <activity-->
<!-- android:name=".CreateAccountActivity"-->
<!-- android:theme="#style/AppTheme.NoActionBar">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
<activity
android:name=".CreateAccountActivity2"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ViewLogActivity"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".LogoutActivity"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
**Main Activity Buttons:**
Button create_account_button = findViewById(R.id.create_account);
create_account_button.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// call the create account activity
Log.d("MainActivity", "onClick for create account called");
Intent intent = new Intent(MainActivity.this, CreateAccountActivity2.class);
startActivity(intent);
}
});
Button login_button = findViewById(R.id.login);
login_button.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// call the login Activity
Log.d("Login", "onClick for login activity called");
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
}
});
Button logout_button = findViewById(R.id.logout);
logout_button.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// call the logout Activity
Log.d("Logout", "onClick for logout activity called");
Intent intent = new Intent(MainActivity.this, LogoutActivity.class);
startActivity(intent);
}
});
Button view_logs_button = findViewById(R.id.viewlogs);
create_account_button.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// call the view log activity
Log.d("MainActivity", "onClick for view log called");
Intent intent = new Intent(MainActivity.this, ViewLogActivity.class);
startActivity(intent);
}
});
Button exit_button = findViewById(R.id.exit);
exit_button.setOnClickListener(new View.OnClickListener(){
// call to exit the application
#Override
public void onClick(View v) {
Log.d("Exit", "onClick for exit called");
finish();
}
});
**Main Activity XML layout File:**
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleX="2"
android:scaleY="2"
android:gravity="center"
android:text="Main Menu"/>
<Button
android:id="#+id/create_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Create Account" />
<Button
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:gravity="center_horizontal"
/>
<Button
android:id="#+id/logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Logout"
android:gravity="center_horizontal"
/>
<Button
android:id="#+id/viewlogs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="View Logs" />
<Button
android:id="#+id/exit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Exit"
android:gravity="center_horizontal"
/>

Issue is here -
you are getting id of view_logs_button but applying click on create_account_button(you apply clicl listener on create_account_button 2 times so its taking latest click listener) and redirecting to ViewLogActivity.
Button view_logs_button = findViewById(R.id.viewlogs);
create_account_button.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// call the view log activity
Log.d("MainActivity", "onClick for view log called");
Intent intent = new Intent(MainActivity.this, ViewLogActivity.class);
startActivity(intent);
}
});
To fix the issue apply click listener on view_logs_button like below -
Button view_logs_button = findViewById(R.id.viewlogs);
view_logs_button.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// call the view log activity
Log.d("MainActivity", "onClick for view log called");
Intent intent = new Intent(MainActivity.this, ViewLogActivity.class);
startActivity(intent);
}
});
Hope this will help you!!

Related

How to solve the error in the AndroidManifest file "Unresolved class 'MainActivity' "?

My AndroidManifest file is showing an error "Unresolved class 'MainActivity' ", but i have a java class and file by that name in the package and it is supposed to be the first activity of the program so when i try to run the program it crashes up , i've checked my code but couldn't find any problem there .
java code for MainActivity file
package com.example.tictactoe;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button forward;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
forward = (Button)findViewById(R.id.start);
forward.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
startActivity(new Intent(MainActivity.this,GameUi.class));
}
});
}
#Override
public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setMessage("Do you want to Exit?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.setNegativeButton("No",new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert=builder.create();
alert.show();
}
}
java code for second activity which my program uses ("GameUi.java")
package com.example.tictactoe
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
public class GameUi extends AppCompatActivity {
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_ui);
btn=(Button)findViewById(R.id.backbtn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(GameUi.this, MainActivity.class));
}
});
}
}
AndroidManifest file code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tictactoe">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.TicTacToe">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GameUi">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity xml file code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E5E6AD"
tools:context=".MainActivity">
<TextView
android:id="#+id/Heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_marginBottom="332dp"
android:editable="false"
android:text="Hello Aliens!"
android:textAlignment="center"
android:textColor="#000000"
android:textSize="50dp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="16dp" />
<ImageView
android:id="#+id/Alienimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/Heading"
app:srcCompat="#drawable/ic_launcher_foreground" />
<Button
android:id="#+id/Startbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000066"
android:letterSpacing="0.5"
android:padding="0dp"
android:text="Start"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Alienimg"
app:layout_constraintVertical_bias="0.886" />
</androidx.constraintlayout.widget.ConstraintLayout>
In your class's I don't see the package at top.
Try adding it and see, if you still face the issue, try invalidate and restarting.
package com.example.tictactoe;
This is the cause of error
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GameUi">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
the intent-filter is used to define that which activity will be your first activity ( when you start your Android Application ). You can use it in both activities so the App will confuse which is your first Activity so they give error.
In case MainActivity is your first activity
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GameUi">
</activity>
Your manifest is Ok ( I guess you fixed the intent-filter issue based on
Abdullah Sheikh answer). the problem is because of this line in MainActivity :
forward = (Button)findViewById(R.id.start);
because your button id is Startbtn not start
just replace that with :
forward = (Button)findViewById(R.id.Startbtn);
also in activity_main and ImageView remove
app:srcCompat="#drawable/ic_launcher_foreground"
or find another src for drawable.

Context for onOptionsItemSelected in app-wide menu

This app has just two activities. MainActivity was renamed to SpecialsActivity. The other activity is PizzaActivity. Using the BottomNavigationView, I want to navigate between the two activities. So far, the app opens in SpecialsActivity, and the pizza button does open the PizzaActivity. But then it will not switch back to the SpecialsActivity. I think the issue is related to context. Please help.
SpecialsActivity.java
public class SpecialsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_specials);
Toolbar myToolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_specials:
Intent specials_intent = new Intent(this, SpecialsActivity.class);
startActivity(specials_intent);
return true;
case R.id.action_pizza:
Intent pizza_intent = new Intent(getApplicationContext(), PizzaActivity.class);
startActivity(pizza_intent);
return true;
default:
// Do nothing
}
return super.onOptionsItemSelected(item);
}
}
activity_specials.xml
<android.support.design.widget.BottomNavigationView
android:layout_width="0dp"
android:layout_height="49dp"
app:itemBackground="#color/colorPrimaryDark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_menu" />
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".SpecialsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PizzaActivity"></activity>
</application>
bottom_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_specials"
android:icon="#drawable/ic_home_black_24dp"
android:title="Specials"
app:showAsAction="always"
android:onClick="onOptionsItemSelected" />
<item
android:id="#+id/action_pizza"
android:enabled="true"
android:icon="#drawable/ic_local_pizza_black_24dp"
android:title="Pizza"
app:showAsAction="always"
android:onClick="onOptionsItemSelected"/>
</menu>
Try changing
Intent pizza_intent = new Intent(getApplicationContext(), PizzaActivity.class);
into this
Intent pizza_intent = new Intent(this, PizzaActivity.class);

Pressing a button is supposed to start service and display text, but nothing happens when I click the button

I'm new to Java and I was trying to make a simple program to display text when a button is pressed by using services. For some reason nothing happens when I press the "Start Service" and "Stop Service" buttons. Here's my code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void startService(View view) {
startService(new Intent(getBaseContext(), MyService.class));
}
public void stopService(View view) {
stopService(new Intent(getBaseContext(), MyService.class));
}
public static class MyService extends Service {
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
#Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}
And the buttons-
<Button
android:id="#+id/button"
android:layout_width="132dp"
android:layout_height="105dp"
android:layout_marginTop="8dp"
android:onClick="startService"
android:text="#string/Buttton1"
android:visibility="visible"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button2"
android:layout_width="128dp"
android:layout_height="108dp"
android:layout_marginTop="8dp"
android:onClick="stopService"
android:text="#string/Button2"
android:visibility="visible"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button" />
A few things wrong.
1: I don't think your service should be static.
2: Did you declare your service in your AndroidManifes.xml?
3: You don't need to use getBaseContext()
If you're in an activity use this
If you're in a fragment use getActivity()
So you have to declare all your services same as all your activities in the android manifest.To do that navigate to your apps manifest located under app>manifest>AndroidManifext.xml.Next, you need to add a service tag under application with the name of your service.
Example code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.android.myapplication">
<application
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<service android:name=".MyService"/> <-----This is were you declared your service
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Everything should work fine after that.
I was using a fragment that's why it wasn't working. I used MainActivity and it worked. Thanks for the answers!

How do I start my game loop after i click a button on welcome page?

I'm making an Android game in Android Studio.
I first wrote the code for game loop. Then I created a a welcome page/start page and added it to the onclick event.
But when I run the app, and click the "start" button, the app stops abruptly. Here is the Java, XML and manifest files. Did I miss something?
My main activity (Game.java):
public class Game extends ActionBarActivity{
private static Button button_sbm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//turn off title
requestWindowFeature(Window.FEATURE_NO_TITLE);
//set to full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_game);
onClickButtonListener();
}
public void onClickButtonListener(){
button_sbm=(Button)findViewById(R.id.button);
button_sbm.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent("com.project.androidgame.GAME");
startActivity(intent);
}
}
);
}
/*public void startGame(){
Intent intent=new Intent(Splash.this, Game.class);
startActivity(intent);
}*/
activity_game.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="START"
android:textSize="50sp"
android:id="#+id/button"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How to play"
android:textSize="24sp"
android:id="#+id/button2"
android:layout_below="#+id/button"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
activity for the starting page (Splash.java):
public class Splash extends Activity {
MediaPlayer ourSong;
#Override
protected void onCreate(Bundle ILoveFootball) {
super.onCreate(ILoveFootball);
setContentView(R.layout.splash);
ourSong=MediaPlayer.create(Splash.this,R.raw.splashsound);
ourSong.start();
Thread timer=new Thread(){
public void run()
{
try{
sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint=new Intent("com.project.androidgame.GAME");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
#Override
protected void onPause() {
super.onPause();
ourSong.release();
finish();
}
}
splash.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/splash_back">
manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:screenOrientation="landscape"
android:name=".Splash" android:label="AndroidGame">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:screenOrientation="landscape"
android:name=".Game" android:label="AndroidGame">
<intent-filter>
<action android:name="com.project.androidgame.GAME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Follow this step to edit your code
In your manifest, remove the intent-filter in the second activity, intent-filter is only use to recognize a start up activity. Change this
<activity android:screenOrientation="landscape"
android:name=".Game" android:label="AndroidGame">
<intent-filter>
<action android:name="com.project.androidgame.GAME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
To this
<activity android:screenOrientation="landscape"
android:name=".Game" android:label="AndroidGame">
</activity>
The best way to start an activity is the present content to the next class an example
Intent intent=new Intent(Splash.this, Game.class);
startActivity(intent);

Bar Code Scanner App. Multiple Handlers On a Single Activity

I have a bar code scanner app that has the following layout...
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/scanner"
android:id="#+id/scan_barcode1"
android:layout_below="#+id/spinner7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="25dp"
android:onClick="openScanner1" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/scan_content"
android:layout_below="#+id/scan_barcode1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="#string/serial_number"
android:layout_alignRight="#+id/spinner7"
android:layout_alignEnd="#+id/spinner7" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/scanner"
android:id="#+id/scan_barcode2"
android:layout_below="#+id/scan_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="openScanner2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/scan_content2"
android:layout_below="#+id/scan_barcode2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="#string/serial_number"
android:layout_alignRight="#+id/scan_content"
android:layout_alignEnd="#+id/scan_content" />
I want to be able to press scan_barcode1 and recieve the serial number of the barcode in editText scan_content, Then press scan_barcode2 and recieve the serial number of that barcode in editText scan_content2. My app crashes when i press either of the two buttons.
public void openScanner1 (View view) {
IntentIntegrator scanIntegrator = new IntentIntegrator (this);
scanIntegrator.initiateScan();
startActivityForResult(scanIntegrator, 1);
}
public void openScanner2 (View view) {
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
scanIntegrator.initiateScan();
startActivityForResult(scanIntegrator, 2);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null && requestCode == 1 && resultCode == RESULT_OK ) {
String scanContent = scanningResult.getContents();
contentTxt.setText(scanContent);
}
else if (scanningResult!=null && requestCode == 2 && resultCode == RESULT_OK) {
String scanContent = scanningResult.getContents();
contentTxt2.setText(scanContent);
}
else{
Toast toast = Toast.makeText(getApplicationContext(),
"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
Here is my logcat...
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1817)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1515)
at android.app.Activity.startActivityForResult(Activity.java:4026)
at android.app.Activity.startActivityForResult(Activity.java:3973)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
at com.example.gamezcua.etaksytemscop.BeforeBatteryInventory.openScanner1(BeforeBatteryInventory.java:521)
Here is my android manifest.
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/etak_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
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=".EditExistingCloseOutPackage"
android:label="#string/title_activity_edit_existing_close_out_package" >
</activity>
<activity
android:name=".SiteInfo"
android:label="#string/title_activity_site_info" >
</activity>
<activity
android:name=".choice"
android:label="#string/title_activity_choice" >
</activity>
<activity
android:name=".NewOrExisting"
android:label="#string/title_activity_new_or_existing" >
</activity>
<activity
android:name=".NewBatteryInformation"
android:label="#string/title_activity_new_battery_information" >
</activity>
<activity
android:name=".ExistingBatteryInformation"
android:label="#string/title_activity_existing_battery_information" >
</activity>
<activity
android:name=".BatteryInstallationChecklist"
android:label="#string/title_activity_battery_installation_checklist" >
</activity>
<activity
android:name=".FinalInstallationChecklistBattery"
android:label="#string/title_activity_final_installation_checklist_battery" >
</activity>
<activity
android:name=".FinalSiteChecklist"
android:label="#string/title_activity_final_site_checklist" >
</activity>
<activity
android:name=".PhotoGallery"
android:label="#string/title_activity_photo_gallery" >
</activity>
<activity
android:name=".BeforeBatteryInventory"
android:label="#string/title_activity_before_battery_inventory" >
</activity>
<activity
android:name=".CompleteOnScopeWork"
android:label="#string/title_activity_complete_on_scope_work" >
</activity>
<activity
android:name=".JobType"
android:label="#string/title_activity_job_type" >
</activity>
<activity
android:name=".AfterInventory"
android:label="#string/title_activity_after_inventory" >
</activity>
<activity
android:name=".Both"
android:label="#string/title_activity_both" >
</activity>
</application>
updated java file
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult!=null) {
String scanContent = scanningResult.getContents();
editText32.setText(scanContent);
}
if (scanningResult != null) {
String scanContent = scanningResult.getContents();
editText33.setText(scanContent);
}
else{
Toast toast = Toast.makeText(getApplicationContext(),
"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
        

Categories