when i write this code why the color of mFacebookCallbackManager changes to red saying cannot resolve symbol mFacebookCallbackManager
public class signin extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
mFacebookCallbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_signin);
}
}
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">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Kindly help me out to solve the problem
You did not declare the variable mFacebookCallbackManager.
Related
I'm trying to use onConfigurationChanged to detect screen rotation.
Activity
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onConfigurationChanged(#NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Toast.makeText(getApplicationContext(), "Screen is rotated!", Toast.LENGTH_SHORT).show();
Log.i("ROTATEAPP", "Screen is rotated...");
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.ScreenRotate"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
I rotated the device (Pixel 3 running Android 12) a few times, and didn't see any Toast or log entry. What's wrong here?
In this project I tried to make an animated splash screen which will appear before going to the main activity, but after I execute, the splash screen does not appear but instead goes directly to the main activity.
how to fix this?
this is my splash activity class
private ImageView container;
private AnimationDrawable animationDrawable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash)
container = findViewById(R.id.iv_icons);
container.setBackgroundResource(R.drawable.mysplash_animation);
animationDrawable = (AnimationDrawable) container.getBackground();
}
#Override
protected void onResume() {
super.onResume();
animationDrawable.start();
checkAnimationStatus(50, animationDrawable);
}
private void checkAnimationStatus(final int time, final AnimationDrawable animationDrawable) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
if (animationDrawable.getCurrent() != animationDrawable.getFrame(animationDrawable.getNumberOfFrames() - 1))
checkAnimationStatus(time, animationDrawable);
else finish();
}
}, time);
}
}
and this is my manifest.xml
<application
android:allowBackup="true"
android:exported="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.NoActionBar">
<activity android:name=".SplashActivity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
You have to change this in your manifest(you have to give launcher activity to splashActivity)
<application
android:allowBackup="true"
android:exported="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.NoActionBar">
<activity android:name=".SplashActivity">
// below code you have to add //
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
//Remove from here//
</activity>
</application>
Set your Splash Activity as the Launcher activity:
<activity android:name=".MainActivity"></activity>
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Please provide intentfilter to SplashActivity
<application
android:allowBackup="true"
android:exported="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.NoActionBar">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
</activity>
</application>
Before my application was working fine. I just created a new class (within the same package) and also declared it in the manifest, still I get a ActivityNotFoundException and sometimes NoClassDefFoundException.
TestActivity.java
public class TestActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.order_summary);
}
}
Activity_NewOrder.java
public class Activity_NewOrder extends Activity
try {
//Also tried Intent intent = new Intent(Activity_NewOrder.this, TestActivity.class);
Intent intent = new Intent(getApplicationContext(), TestActivity.class);
startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mypackage">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".Activities.Activity_OrderSummaryNew"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity
android:name=".Activities.Activity_Login"
android:configChanges="orientation"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activities.Activity_Orders"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity
android:name=".Activities.Activity_NewOrder"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity
android:name=".Activities.Activity_OrderHistory"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape" />
<activity android:name=".Activities.TestActivity" />
</application>
</manifest>
I'm trying to implement Facebook login button, but i'm receiving these errors when trying to run app:
Error:
FATAL EXCEPTION: AsyncTask #4
Process: , PID: 4633
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:746)
at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:774)
at com.facebook.internal.Utility.queryAppSettings(Utility.java:825)
at com.facebook.login.widget.LoginButton$1.run(LoginButton.java:489)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
com.android.vlada.sportisa E/GoogleApiAvailability: Google Play services is invalid. Cannot recover.
Code:
public class MainActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener {
private Button buttonRegistrujSe, buttonPrijaviSeKaoGost, buttonPrijavaRegistrovaniKorisnik;
private LoginButton loginButton;
private CallbackManager callbackManager;
private TextView info;
#Override
protected void onCreate(Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
buttonRegistrujSe = (Button) (findViewById(R.id.button_registruj_se));
buttonRegistrujSe.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, RegistrationActivity.class);
startActivity(i);
}
});
buttonPrijaviSeKaoGost = (Button) (findViewById(R.id.button_prijavi_se_kao_gost));
buttonPrijaviSeKaoGost.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i2 = new Intent(MainActivity.this, LoginGostActivity.class);
startActivity(i2);
}
});
buttonPrijavaRegistrovaniKorisnik = (Button) (findViewById(R.id.button_prijava_registrovani_korisnik));
buttonPrijavaRegistrovaniKorisnik.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i3 = new Intent(MainActivity.this, LoginActivity.class);
startActivity(i3);
}
});
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_main);
info = (TextView)findViewById(R.id.info);
loginButton = (LoginButton)findViewById(R.id.connectWithFbButton);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
info.setText(
"User ID: "
+ loginResult.getAccessToken().getUserId()
+ "\n" +
"Auth Token: "
+ loginResult.getAccessToken().getToken()
);
}
#Override
public void onCancel() {
info.setText("Login attempt canceled.");
}
#Override
public void onError(FacebookException e) {
info.setText("Login attempt failed.");
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
#Override
protected void onDestroy() {
super.onDestroy();
System.exit(0);
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
}
}
Layout Code
<com.facebook.login.widget.LoginButton
android:id="#+id/connectWithFbButton"
style="#style/com_facebook_loginview_default_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_above="#+id/sign_in_button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="43dp" />
Update: after i deleted duplicate code in MainActivity i'm still receiving the same errors when trying to ran app. I'm attaching Manifest code also as requested so maybe that would help? Thanx
<?xml version="1.0" encoding="utf-8"?>
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<permission
android:name="com.android.vlada.sportisa.Entiteti.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.android.vlada.sportisa.Entiteti.maps.permission.MAPS_RECEIVE" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAVb2JuN-5nbaVkGODivuXPJOF5OeRekzo" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_login" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" />
<activity android:name=".SplashActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".RegistrationActivity" />
<activity android:name=".LoginActivity" />
<activity android:name=".BiranjeAktivnosti" />
<activity
android:name=".Trazim"
android:label="#string/title_activity_trazim"
android:theme="#style/AppTheme" />
<activity
android:name=".Organizujem"
android:label="#string/title_activity_organizujem"
android:theme="#style/AppTheme" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
</application>
Add metadata inside application tag before activities.
What you have now is:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAVb2JuN-5nbaVkGODivuXPJOF5OeRekzo" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_login" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" />
<activity android:name=".SplashActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
...
</application>
Move metadata inside application tag like this:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAVb2JuN-5nbaVkGODivuXPJOF5OeRekzo" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_login" />
<activity android:name=".MainActivity" />
<activity android:name=".SplashActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
...
</application>
Have you added this code in manifest file.
You also need to add the application id like this:
<application android:label="#string/app_name" ...>
...
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
...
</application>
Don't what, but there's an issue with either FacebookActivity name or the support for Gradle Version 2.3.0 is removed. I faced the same issue and with the following I got rid of this.
Replaced <activity> tag
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
with the <meta> tag.
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/fb_id" />
EDIT
Also, I have placed this <meta> tag at the bottom of the file below, all the activities, above the closing tag.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exampl.fitindya"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="20" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_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>
<!-- Entry for RegisterActivity.class -->
<activity android:name=".RegisterActivity"
android:label="Register New Account"></activity>
</application>
Don't know why this error is appearing and application crashes. please help guys.can there be any problem anywhere else
here is my class file
public class MainActivity extends ActionBarActivity {
Button login_b1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
TextView registerScreen = (TextView) findViewById(R.id.link_to_register);
// Listening to register new account link
registerScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
startActivity(i);
}
});
}
}
Place this code below the register Activity. I guess that should be the error
<intent-filter>
<action android:name="android.intent.action.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>