I tried to make social module for my app, something like wrapper, that will contain Google+,Facebook and twitter integration templates.
Now I am working with Facebook SDK and decided to use LeakCanary in my app, after successful log in I rotated the device few times, and see the following information:
Here is MainActivity.class:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setFragment();
}
private void setFragment(){
getSupportFragmentManager()
.beginTransaction()
.add(R.id.container, new MainFragment())
.commit();
}
}
Here is how I log in to Facebook:
public void configureFacebook(#NonNull Fragment fragment,
#Nullable String permissions, #Nullable String requestFields) {
setPermissionAndRequestFields(permissions, requestFields);
loginManager = LoginManager.getInstance();
callbackManager = CallbackManager.Factory.create();
loginManager.registerCallback(callbackManager, facebookCallback);
loginManager.logInWithReadPermissions(fragment, Arrays.asList(this.permissions));
loginManager=null;
}
I tried log in using Login Button too, in this case I catch this issue and new one, with following info:
Here is how I log in using LoginButton.class:
public void configureFacebook(#NonNull Fragment fragment,
#Nullable String permissions, #Nullable String requestFields, #NonNull LoginButton button) {
callbackManager = CallbackManager.Factory.create();
setFbButton(button);
setPermissionAndRequestFields(permissions, requestFields);
fbButton.setFragment(fragment);
fbButton.setReadPermissions(this.permissions);
fbButton.registerCallback(callbackManager, facebookCallback);
}
I can't figure out how to fix those issues. What I am doing wrong?
UPDATE: Leak in Facebook Activity.class has been shown without the rotation device.
Looks like they may have fixed this for Facebook SDK Version 4.2.0. see here
Updating the Facebook SDK may be the solution to your problem.
I updated it to 4.7.0 and I think this issue has been fixed.
Fixed in 4.10. I tried without facebook app and checked with memory manager.
Related
After I successfully launching the following intent:
startActivity(new Intent(Intent.ACTION_VIEW, SOME_URL));
The browser boots up fine and loads the link, but when I try to return to my app the response is sluggish. When the app eventually launches I am met with a black screen, and finally an "Application Not Responding" dialog.
No errors in logcat, no obvious memory issues, nothing to indicate what I did wrong.
The activity that launches the intent is a pretty simple activity, with one fragment:
public class LinkActivity extends AppCompatActivity {
#BindView(R.id.toolbar) Toolbar mToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_link);
ButterKnife.bind(this);
setSupportActionbar(mToolbar);
setupActionBar();
if(savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.content, LinkFragment.newInstance()).commit();
}
}
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
}
}
}
And the fragment uses a combination of RxJava, RetroFit and Dagger ‡ to load a list of links:
public class LinkFragment extends Fragment {
#Inject RestService mRestService;
#BindView(R.id.recycler) RecyclerView mRecyclerView;
public static LinkFragment newInstance() {
return new LinkFragment();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_link, container, false);
Injector.getContextComponent().inject(this);
ButterKnife.bind(this, view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext());
mRecyclerView.addItemDecoration(new DividerDecoration(getContext());
mRecyclerView.setAdapter(new LinkAdapter(new ArrayList<>()));
mRestService.getLinks()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onNext, this::onError);
return view;
}
private void onNext(Response<Link> response) [
LinkAdapter adapter = new LinkAdapter(response.data());
adapter.setOnItemClickListener(this::onItemSelected);
mRecyclerView.swapAdapter(adapter, false);
}
private void onError(Throwable throwable) {
Timber.w(throwable, "Failed to obtain links");
}
private void onItemSelected(int position, View view, Link link) {
startActivity(new Intent(Intent.ACTION_VIEW, link.getUri());
}
}
After finding two similar questions with similar answers (How to spot app freeze causes when app is returning from pause state?, Android App freezes after implementing Google Firebase) suggesting that adding Google Play Services might be the culprit, I started to investigate.
Both answers suggested that I remove the following dependency:
compile 'com.android.gms:play-services:9.0.2'
But my application uses that dependency, as well as the following play services dependencies:
compile 'com.google.android.gms:play-services-wearable:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile 'com.google.android.gms:play-services-location:9.0.2'
compile 'com.google.android.gms:play-services-analytics:9.0.2'
Previously, I had been using classes from both the core play services library and the wearable play services library in both my mobile module and my wear module. But I noticed that I had removed the need for the wear module in my mobile module, so I removed it from the mobile module (while keeping it in the wear module). Somehow, this fixed the issue.
I have no clue why, so if anyone has any thoughts, please share.
I tried to use GuidedStepFragment to organize settings of my tv app. I run into with problem, that step option work like EditText field, but I don't use GuidedAction.Builder.editable() method.
Settings fragment code
public static class SettingsFragment extends GuidedStepSupportFragment {
#Override
public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
String title = "Настройки1";
String description = "Настройки2";
String breadcrumb = "Настройки3";
Drawable icon = getActivity().getResources().getDrawable(R.drawable.app_icon_quantum);
return new GuidanceStylist.Guidance(title, description, breadcrumb, icon);
}
#Override
public void onCreateActions(#NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
actions.add(new GuidedAction.Builder()
.id(1)
.infoOnly(true)
.title("Адрес сервера")
.build());
}
}
How I add fragment
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GuidedStepSupportFragment.add(getSupportFragmentManager(), new SettingsFragment());
}
Android Studio version: Beta 4
Gradle plugin version: 2.0.0-beta4
Build tools version: 23.0.2
After some investigation I notice that these bug appears only when app running on tablet, or I try to navigate via mouse on emulator.
I'm working on Xamarin.Forms app with Parse backend. I am trying to integrate Facebook Android SDK into that. What I want to do is to get the access token natively on each device, and push that access token to Parse.com. For that I need to use official facebook sdk binding for Xamarin. I use dependency injection for that. so I have IFacebookService
public interface IFacebookService
{
Task<string> GetFacebookToken();
void LogOut();
}
And on each platform I implement FacebookService and inject that implementation. On iOS I had no problems. On Android the problem is that even though the facebook UI is shown, I don't receive the callbacks inside my implementation of FacebookService. I think that has something to do with how Android manages callbacks as well as how Xamarin.Forms creates activities. Let me go through the code. Here is the portion of code to request login from Facebook
var callbackManager = CallbackManagerFactory.Create();
//Here I instantiate my own implementation of IFacebookCallback
//nothing fancy here, I've just implemented the required methods with Console.WriteLine();
var loginCallback = new FacebookCallback(() => _loginInProgress = false);
//Register callbackManager and my instance of loginCallback
LoginManager.Instance.RegisterCallback (callbackManager, loginCallback);
//Here is the important part. I need an activity to show the login UI
//Xamarin forms provides me with this method.
var activity = Xamarin.Forms.Forms.Context as Activity;
//I request login
LoginManager.Instance.LogInWithReadPermissions(activity, new string[] { "public_profile", "email", "user_friends" });
So, I believe the problem is within this line
var activity = Xamarin.Forms.Forms.Context as Activity;
In the debugger I see that MainActivity is returned, which is my entry point (MainLauncher = true), and where I call Xamarin Form's initialisation methods
//Setup Xamarin forms
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new FormsApp());
The initial page that is registered in FormsApp is call LoginPage. So I believe that it is loaded as a fragment inside main activity. So, perhaps I'll need to do something like this
LoginManager.Instance.LogInWithReadPermissions(LOGIN_PAGE_FRAGMENT,......);
because in facebook sdk there are separate versions for activity and fragment. I don't know exactly how to get LOGIN_PAGE_FRAGMENT, perhaps even the issue is in some other place, which I don't understand.
Do you have any ideas what can cause the issue?
I've resolved the issue! I've found something similar here
Although my approach is a little different, but the main issue was that I needed to add the implementation of OnActivityResult to the MainActivity and create CallbackManager inside the MainActivity and delegate the OnActivityResult to that CallbackManager. So in MainActivity I added this property
public ICallbackManager CallbackManager { get; private set; }
Then I've overridden OnActivityResult like this
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
CallbackManager.OnActivityResult(requestCode, (int)resultCode, data);
}
Then I've replaced the previous login code with this
var loginCallback = new FacebookCallback(() => _loginInProgress = false);
var activity = Xamarin.Forms.Forms.Context as MainActivity;
LoginManager.Instance.RegisterCallback (activity.CallbackManager, loginCallback);
LoginManager.Instance.LogInWithReadPermissions(activity, new string[] { "public_profile", "email", "user_friends" });
And Everything worked! Hope this will help someone.
I tried to made button that goes to webpages but when I lunch app it crushes. There are no errors tos. What to do? Mby there is a problem in XML?
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
addButtonClickListener(); //Soc network buttons
}
public void addButtonClickListener() //soc network buttons
{
Button facebook = (Button)findViewById(R.id.Facebookpoga); //Facebook pogai
facebook.setOnClickListener(new OnClickListener(){
public void onClick(View arg)
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com"));
startActivity(intent);
}
});
}
I had encountered a similar problem, lot of times while learning the basics of Android development. And I can tell that the problem is that, for some reasons findViewById(id) returns null. This started happening after an update when eclipse started including a Fragment layout with the main layout for each Activity.
I sorted out the problems by putting all such calls in onStart() instead of onCreate(). And I am sure that sorts out the problem for you to.
Do this:
protected void onStart(){
addButtonClickListener(); //Soc network buttons
}
Add this function after onCreate(), hope it helps. And yes, remove the listener call addButtonClickListener(); from onCreate().
I guess the problem may be because Fragment layout is not instantinated immediately after setContentView() which results in findViewById(R.id.Facebookpoga); to return null, because no such View with id R.id.Facebookpoga is created yet.
I am searching for a long time and i was not successful yet .
Is there any method to specify the privacy setting while logging into the facebook itself through native login , so that whatever activities i do on facebook through app , posts in facebook with the specified privacy settings .
i am following the below link http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/ for setting up the facebook native login .
while searching i found some codes for ios , they have something like
FBSessionDefaultAudienceEveryone
FBSessionDefaultAudienceALL_FRIENDS
FBSessionDefaultAudienceSELF
for privacy settings . But is there anything for android ?
i have added my code ,
public class SplashFragment extends Fragment
{
LoginButton authButton;
//private static final List<String> PERMISSIONS = Arrays.asList("user_photos","email","user_status","friends_status","user_videos","user_checkins","friends_checkins","offline_access","user_actions.news","user_actions:parii_apps","user_events","friends_events");
//private static final List<String> PERMISSION = Arrays.asList("publish_actions","publish_stream","publish_checkins","manage_pages","create_event","rsvp_event");
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.splash, container, false);
authButton = (LoginButton) view.findViewById(R.id.fb_logIn_btn);
authButton.setDefaultAudience(SessionDefaultAudience.ONLY_ME);
Log.e(" setDefaultAudience ", " is "+authButton.getDefaultAudience());
return view;
}
}
this is not working for me
Any related answers are welcomed . Thanks in advance .
Yes.
Default audience only comes into play when you request for publish permissions, which you need to do through a session.requestForNewPublishPermissions() call with a NewPermissionsRequest object.
You can set a default audience on the NewPermissionsRequest object, see the javadocs here: https://developers.facebook.com/docs/reference/android/3.0/Session.NewPermissionsRequest