I am having a trouble on open the contact from my contact list page it was working fine but when i touch the user to open the messages activity so it should start chatting there.
This is my messages activity:
public class MessageActivity extends AppCompatActivity {
CircleImageView imageView;
FirebaseUser firebaseUser;
DatabaseReference reference;
Intent intent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
imageView = findViewById(R.id.profile_image);
intent = getIntent();
String userid = intent.getStringExtra("userid");
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
reference = FirebaseDatabase.getInstance().getReference("parent").child(userid);
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
if (user.getImageURL().equals("default")) {
imageView.setImageResource(R.drawable.ic_user);
}else {
Glide.with(MessageActivity.this).load(user.getImageURL()).into(imageView);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
And this is the intent i was calling for:
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(context, MessageActivity.class);
intent.putExtra("userid", user.getId());
context.startActivity(intent);
}
});
This is my logcat when i run the app:
2020-05-01 20:39:12.857 12974-12974/net.gobz.gobz E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.gobz.gobz, PID: 12974
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:994)
at android.app.ContextImpl.startActivity(ContextImpl.java:970)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:389)
at net.gobz.gobz.Adapter.UserAdapter$1.onClick(UserAdapter.java:54)
After reading your logcat , which is saying that you have to use Flags to your IntentActivity so try with replacing your code with this one.
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(context, MessageActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("userid", user.getId());
context.startActivity(intent);
}
});
Related
So I defined a switch button in ProfileSettingsfragment but i am using that button in Explanation.class. What I am really trying to do is when switch button is checked i want start service else i don't want to star service from Explanation.class
SO I tried Some code and it showing me this error " java.lang.NullPointerException: Attempt to invoke virtual method 'boolean androidx.appcompat.widget.SwitchCompat.isChecked()' on a null object reference
at com.harsh.preacher.ui.Home.Explaination$1.onClick(Explaination.java:43)"
P.S I have designed switch button in ProfileSettingsfragment.xml
Here is ProfileSettingsfragment class code
public class ProfileSettingsFragment extends Fragment {
private GoogleSignInClient mGoogleSignInClient;
public SwitchCompat notePopUp;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_profilesettings, container, false);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(requireContext(), gso);
final ProfileSettingsFragment profileSettingsFragment =new ProfileSettingsFragment();
Button signOut1 = root.findViewById(R.id.signOut);
signOut1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//TODO Custom Alert Dialog Bar
// signOut();
Intent intent = new Intent(getContext(), AndarAwoo.class);
startActivity(intent);
// Animation(signOut1);
}
});
notePopUp = (SwitchCompat) root.findViewById(R.id.notePopUp);
RelativeLayout EditName = root.findViewById(R.id.EditName);
RelativeLayout ProfileSettingsLayout= root.findViewById(R.id.profileSettingsCardView);
TextView EditNameText = root.findViewById(R.id.EditNameText);
EditNameText.setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.KITKAT)
#Override
public void onClick(View view) {
if(EditName.getVisibility() == View.GONE){
TransitionManager.beginDelayedTransition(ProfileSettingsLayout,new AutoTransition());
EditName.setVisibility(View.VISIBLE);
}else {
TransitionManager.beginDelayedTransition(ProfileSettingsLayout,new AutoTransition());
EditName.setVisibility(View.GONE);
}
}
});
return root;
}
Here is my explanation class code
public class Explaination extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_explaination);
Intent intent = getIntent();
String about = intent.getStringExtra("about");
TextView about1 = findViewById(R.id.about);
about1.setText(about);
Button resource = findViewById(R.id.Resource);
resource.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = getIntent();
String url = intent.getStringExtra("button");
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
ProfileSettingsFragment checkNotePopUp = new ProfileSettingsFragment();
checkNotePopUp.notePopUp = findViewById(R.id.notePopUp);
if(checkNotePopUp.notePopUp.isChecked()){
startService(new Intent(Explaination.this, NotePopUpHead.class));
}
else{
stopService(new Intent(Explaination.this,NotePopUpHead.class));
}
finish();
startActivity(i);
}
});
}
}
I have more than three activities and these other activities transition so well but one activity which I have included the code for below appear to be jumping every time I navigate to it.
I have overridden the animation class but the jump still persists.How can I go about it? Is my Ui thread overloaded?
public class ListActivity extends AppCompatActivity implements
RecyclerViewAdapter.OnItemClickListener {
RecyclerViewAdapter recyclerViewAdapter;
RecyclerView recyclerView;
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference dbRef = db.collection("Archives");
Context context;
FloatingActionButton fab;
Item clickedItem;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
recyclerView = findViewById(R.id.recyclerView);
fab = findViewById(R.id.fab);
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
});
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(ListActivity.this,
EnterDataActivity.class);
startActivity(intent);
}
});
setUpAdapter();
}
private void setUpAdapter() {
Query query = dbRef.orderBy("fname", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Item> options = new
FirestoreRecyclerOptions.Builder<Item>()
.setQuery(query, Item.class)
.build();
recyclerViewAdapter = new RecyclerViewAdapter(options,
ListActivity.this);
recyclerViewAdapter.notifyDataSetChanged();
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setAdapter(recyclerViewAdapter);
recyclerViewAdapter.setOnItemClickListener(ListActivity.this);
}
#Override
public void onStart() {
super.onStart();
recyclerViewAdapter.startListening();
}
#Override
public void onStop() {
super.onStop();
recyclerViewAdapter.stopListening();
}
#Override public void onItemClick(DocumentSnapshot documentSnapshot, int
position) {
clickedItem = documentSnapshot.toObject(Item.class);
clickedItem.setId((documentSnapshot.getId()));
Intent intent = new Intent(ListActivity.this, DetailActivity.class);
intent.putExtra(First_Name, clickedItem.getFname());
intent.putExtra(Middle_Name, clickedItem.getMname());
intent.putExtra(Sur_Name, clickedItem.getSname());
intent.putExtra(Email, clickedItem.getEmail());
intent.putExtra(phone, clickedItem.getPhone());
intent.putExtra(city, clickedItem.getCity());
intent.putExtra(parents_Name, clickedItem.getParentsName());
intent.putExtra(parents_Phone, clickedItem.getParentsContact());
intent.putExtra(dob, clickedItem.getDob());
intent.putExtra(emergency, clickedItem.getEmergency());
intent.putExtra(profile_Picture, clickedItem.getProfilePicture());
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
startActivityForResult(intent, 45);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == 45 && resultCode == RESULT_OK && data != null)) {
String fname = data.getStringExtra(First_Name);
String mname = data.getStringExtra(Middle_Name);
String sname = data.getStringExtra(Sur_Name);
String email = data.getStringExtra(Email);
String Phone = data.getStringExtra(phone);
String City = data.getStringExtra(city);
String pname = data.getStringExtra(parents_Name);
String pphone = data.getStringExtra(parents_Phone);
String Dob = data.getStringExtra(dob);
String Emergency = data.getStringExtra(emergency);
String profile = data.getStringExtra(profile_Picture);
Item items = new Item(fname, mname, sname, email, Phone, City,
pname, pphone, Dob, Emergency, profile);
db.collection("Archives").document(clickedItem.getId())
.set(items).addOnSuccessListener(new
OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
Toast.makeText(ListActivity.this, "Updated Successfully",
Toast.LENGTH_LONG).show();
}
});
}
}
}
Activity documentation of overridePendingTransition says:
Call immediately after one of the flavors of startActivity(android.content.Intent) or finish() to specify an explicit transition animation to perform next.
So calling overridePendingTransition in any other places at least does nothing. Remove such calls like in ListActivity#onCreate after setContentView and place them next line to startActivity or startActivityForResult.
I have created a new layout name dialog_exit for onBackPressed but when I install and open, my application can not open and showing error close app
Please review my whole code and guide me how can I solve this problem
Here is my main activity code
public class MainActivity extends AppCompatActivity {
public Dialog mDialog;
public Button mDialogyes, mDialogno;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createDialog();
}
private void createDialog() {
mDialog = new Dialog(this);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.dialog_exit);
mDialog.setCanceledOnTouchOutside(true);
mDialog.setCancelable(true);
mDialogyes = (Button) findViewById(R.id.yes);
mDialogno = (Button) findViewById(R.id.no);
mDialogyes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
finish();
System.exit(0);
mDialogno.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDialog.dismiss();
}
});
}
});
}
#Override
public void onBackPressed() {
mDialog.show();
}
}
Here is my layout code as screenshot because
stackoverflow not allow me to add more code that why sharing image
Updated code of createDialog function
private void createDialog() {
mDialog = new Dialog(this);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.dialog_exit);
mDialog.setCanceledOnTouchOutside(true);
mDialog.setCancelable(true);
mDialogyes = (Button) mDialog.findViewById(R.id.yes);
mDialogno = (Button) mDialog.findViewById(R.id.no);
mDialogyes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
finish();
System.exit(0);
}
});
mDialogno.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDialog.dismiss();
}
});
}
try this code
mDialogyes = (Button)mDialogyes. findViewById(R.id.yes);
mDialogno = (Button)mDialogyes. findViewById(R.id.no);
mDialogyes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
finish();
System.exit(0);
}
});
mDialogno.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDialog.dismiss();
}
});
You have to do like this
mDialogyes = (Button) mDialog.findViewById(R.id.yes);
mDialogno = (Button) mDialog.findViewById(R.id.no);
`public class MainActivity extends Activity {
ImageButton button1;
ImageButton button2;
ImageButton button3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton(){
button1 = (ImageButton)findViewById(R.id.Button1);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
});
button2 = (ImageButton)findViewById(R.id.Button2);
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, ThirdActivity.class);
startActivity(intent);
}
});
button3 = (ImageButton)findViewById(R.id.Button3);
button3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, ForthActivity.class);
startActivity(intent);
}
});
}
}
`I'm stuck with building an apk, using Android Studio. Messages Gradle Build always shows ":app:mergeReleaseResource FAILD". I wonder if there are something wrong with .png file.The picture shows the details in Messages Gradle Build
A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
I am trying to log in and sign up using my application and found the above error.
Following is my code of main activity.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (ParseAnonymousUtils.isLinked(ParseUser.getCurrentUser())) {
Intent intent = new Intent(MainActivity.this, LoginSignupActivity.class);
startActivity(intent);
finish();
} else {
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
Intent intent = new Intent(MainActivity.this, Welcome.class);
startActivity(intent);
finish();
} else {
Intent intent = new Intent(MainActivity.this, LoginSignupActivity.class);
startActivity(intent);
finish();
}
}
}
}
Following is my code of LoginSigupActivity
public class LoginSignupActivity extends ActionBarActivity {
Button loginButton;
Button signupButton;
#Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.activity_login_signup);
loginButton = (Button) findViewById(R.id.btn_launcherSignIn);
signupButton = (Button) findViewById(R.id.btn_launcherSignUp);
loginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(LoginSignupActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
});
signupButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(LoginSignupActivity.this, SignUpActivity.class);
startActivity(intent);
finish();
}
});
}
}
Folloing is my login activity class code
public class LoginActivity extends ActionBarActivity {
Button loginButton;
String txtUsername;
String txtPassword;
EditText password;
EditText username;
#Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.activity_login);
loginButton = (Button) findViewById(R.id.login);
loginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txtUsername = username.getText().toString();
txtPassword = password.getText().toString();
ParseUser.logInInBackground(txtUsername, txtPassword, new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if (user != null) {
Intent intent = new Intent(LoginActivity.this, Welcome.class);
startActivity(intent);
finish();
} else {
Toast.makeText(getApplicationContext(), "This user does not exist! Please Sign up", Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}
Following is my signup activity code
public class SignUpActivity extends ActionBarActivity {
Button signupButton;
String txtUsername;
String txtPassword;
EditText password;
EditText username;
#Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.activity_signup);
signupButton = (Button) findViewById(R.id.signup);
signupButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txtUsername = username.getText().toString();
txtPassword = password.getText().toString();
if(txtUsername.equals("") && txtPassword.equals("")){
Toast.makeText(getApplicationContext(), "Please complete the signup form", Toast.LENGTH_SHORT).show();
}else{
ParseUser user = new ParseUser();
user.setUsername(txtUsername);
user.setPassword(txtPassword);
user.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
if(e==null){
Toast.makeText(getApplicationContext(), "Signed up successfully...!", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "Signup Error", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
}
}
And following is my Parse connector class code
public class ParseConnecter extends MultiDexApplication{
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "zblr0TmjldGaV2xSl5******aFhe6DW78FjA2u", "9Ys6j7uY68115********2pvo5Ldfia");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}