This is my non-activity class:
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class PostManager {
private Bundle bundle;
private Context context;
private Session session;
private String victimId=null;
public PostManager() {
SavedFriend savedFriend = new SavedFriend();
bundle = savedFriend.getBundle();
context = savedFriend.getContext();
session = savedFriend.getSession();
victimId = savedFriend.getfriendsId();
Log.e("postManager", victimId);
Log.e("postManager", bundle.getString("message"));
}
}
This is my application class:
import java.util.List;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import com.facebook.Session;
import com.facebook.model.GraphUser;
public class SavedFriend extends Application {
private List<GraphUser> selectedUsers;
private String friendsId;
private Session session;
private Bundle bundle;
private Context context;
public List<GraphUser> getSelectedUsers() {
return selectedUsers;
}
public void setSelectedUsers(List<GraphUser> selectedUsers) {
this.selectedUsers = selectedUsers;
}
public String getfriendsId() {
return friendsId;
}
public void setfriendsId(String id) {
this.friendsId = id;
}
public Session getSession(){
return session;
}
public void setSession(Session session){
this.session = session;
}
public void setContext(Context context){
this.context = context;
}
public Context getContext(){
return context;
}
public void setBundle(Bundle bundle){
this.bundle = bundle;
}
public Bundle getBundle(){
return bundle;
}
}
I have used the data of the application class in a fragment class (friendsId)
which is not null.
When I call the application class's data from PostManager
it returning the value null.
I have tried to see the value of friendsId
and message
by Log.e
. but it gives me nullPointer exception.
Does that means all of the values I call in my PostManager constructor
from application class are null? If yes, what should I do?
I need the session, applicationcontext, message, friendsId value in my PostManager
class. I can pass these values to PostManager
, but this class is called by onReceive()
of alarm class
which class extends BroadcastReceiver
, and this alarm is set from another class which extend Fragment
. All the values I need are created by this class except friendsId
, and I don't know how to pass these value from first class->alarm class->postmanager class.
In manifest for alarm class:
<application android:name=".SavedFriend"
.......>
....
<receiver android:name="package name.Alarm"/>
....
</application>