Я мог бы действительно использовать вашу помощь с этим. Я делаю клон Instagram и использую фрагменты, у меня есть один для страницы профиля. В нем у меня есть кнопка, которая переходит к AccountSettingsActivity, где вы можете редактировать информацию о пользователе, у меня есть кнопка, чтобы сохранить изменения, и еще одна, чтобы вернуться к фрагменту профиля, но когда я использую последний, приложение вылетает, и появляется это сообщение. :
Невозможно найти явный класс активности {academy.epicprogramming.kynoanimalrescue / academy.epicprogramming.kynoanimalrescue.fragments.ProfileFragment}; Вы объявили это действие в своем AndroidManifest. xml?
, и это файл манифеста:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="academy.epicprogramming.kynoanimalrescue">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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=".Main2Activity"-->
<!-- android:label="@string/title_activity_main2"></activity>-->
<activity android:name=".AccountSettingsActivity" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBYtQl--ajXZy1uzOZoXSNGJLCeyAHUV9s" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name=".Login.SignUpActivity" />
<activity android:name=".Login.SignInActivity" />
<activity android:name=".Intro.IntroSlider" />
<activity android:name=".MainActivity" />
<activity
android:name=".Intro.SplashScreen"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat"/> <!-- optional (needed if default theme has no action bar) -->
</application>
</manifest>
Это кнопка для go возврата к ProfileFragment файл
close_profile_btn.setOnClickListener {
val intent = Intent(this@AccountSettingsActivity, ProfileFragment::class.java)
startActivity(intent)
finish()
}
, и это полный файл AccountSettingsActivity
class AccountSettingsActivity : AppCompatActivity() {
private lateinit var firebaseUser: FirebaseUser
private var checker = ""
private var myUrl = ""
private var imageUri: Uri? = null
private var storageProfilePictureRef: StorageReference? = null
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_account_settings)
firebaseUser = FirebaseAuth.getInstance().currentUser!!
storageProfilePictureRef =
FirebaseStorage.getInstance().reference.child("Profile Pictures")
logout_btn.setOnClickListener {
FirebaseAuth.getInstance().signOut()
val intent = Intent(this@AccountSettingsActivity, ProfileFragment::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
finish()
}
close_profile_btn.setOnClickListener {
val intent = Intent(this@AccountSettingsActivity, ProfileFragment::class.java)
startActivity(intent)
finish()
}
change_image_text_btn.setOnClickListener {
checker = "clicked"
CropImage.activity()
.setAspectRatio(1, 1)
.start(this@AccountSettingsActivity)
}
save_info_profile_btn.setOnClickListener {
if (checker == "clicked") {
updateImageAndInfo()
} else {
updateUserInfoOnly()
}
}
userInfo()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null)
{
val result = CropImage.getActivityResult(data)
imageUri = result.uri
profile_image_view_profile_frag.setImageURI(imageUri)
}
}
private fun updateUserInfoOnly() {
when {
full_name_profile_frag.text.toString() == "" -> Toast.makeText(
this,
"Please enter your name",
Toast.LENGTH_LONG
).show()
username_profile_frag.text.toString() == "" -> Toast.makeText(
this,
"Please enter your username",
Toast.LENGTH_LONG
).show()
bio_profile_frag.text.toString() == "" -> {
bio_profile_frag.setText("Estoy usando Kyno animal rescue")
val usersRef =
FirebaseDatabase.getInstance().reference.child("Users")
val userMap = HashMap<String, Any>()
userMap["fullname"] = full_name_profile_frag.text.toString().toLowerCase()
userMap["username"] = username_profile_frag.text.toString()
userMap["bio"] = bio_profile_frag.text.toString()
usersRef.child(firebaseUser.uid).updateChildren(userMap)
Toast.makeText(this, "Account information successfully updated", Toast.LENGTH_LONG)
.show()
val intent = Intent(this@AccountSettingsActivity, MainActivity::class.java)
startActivity(intent)
finish()
}
else -> {
val usersRef =
FirebaseDatabase.getInstance().reference.child("Users")
val userMap = HashMap<String, Any>()
userMap["fullname"] = full_name_profile_frag.text.toString().toLowerCase()
userMap["username"] = username_profile_frag.text.toString()
userMap["bio"] = bio_profile_frag.text.toString()
usersRef.child(firebaseUser.uid).updateChildren(userMap)
Toast.makeText(this, "Account information successfully updated", Toast.LENGTH_LONG)
.show()
val intent = Intent(this@AccountSettingsActivity, MainActivity::class.java)
startActivity(intent)
finish()
}
}
}
private fun userInfo() {
val usersRef =
FirebaseDatabase.getInstance().getReference().child("Users").child(firebaseUser.uid)
usersRef.addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
if (dataSnapshot.exists()) {
val user = dataSnapshot.getValue<User>(User::class.java)
Picasso.get().load(user!!.getImage()).placeholder(R.drawable.profile)
.into(profile_image_view_profile_frag)
full_name_profile_frag.setText(user.getFullname())
username_profile_frag.setText(user.getUsername())
bio_profile_frag.setText(user.getBio())
}
}
override fun onCancelled(p0: DatabaseError) {
}
})
}
private fun updateImageAndInfo() {
when {
imageUri == null -> Toast.makeText(
this,
"Please choose a picture",
Toast.LENGTH_LONG
).show()
full_name_profile_frag.text.toString() == "" -> Toast.makeText(
this,
"Please enter your name",
Toast.LENGTH_LONG
).show()
username_profile_frag.text.toString() == "" -> Toast.makeText(
this,
"Please enter your username",
Toast.LENGTH_LONG
).show()
bio_profile_frag.text.toString() == "" -> {
Toast.makeText(
this,
"Please enter your bio",
Toast.LENGTH_LONG
).show()
}
// CODE TO SET A DEFAULT BIO IF USER DOESN'T ENTER ONE
// bio_profile_frag.text.toString() == "" -> {
// bio_profile_frag.setText("Estoy usando Kyno animal rescue")
//
// val usersRef =
// FirebaseDatabase.getInstance().reference.child("Users")
// val userMap = HashMap<String, Any>()
// userMap["fullname"] = full_name_profile_frag.text.toString().toLowerCase()
// userMap["username"] = username_profile_frag.text.toString()
// userMap["bio"] = bio_profile_frag.text.toString()
//
// usersRef.child(firebaseUser.uid).updateChildren(userMap)
//
// Toast.makeText(this, "Account information successfully updated", Toast.LENGTH_LONG)
// .show()
//
// val intent = Intent(this@AccountSettingsActivity, MainActivity::class.java)
// startActivity(intent)
// finish()
// }
else -> {
val progressDialog = ProgressDialog(this)
progressDialog.setTitle("Account Settings")
progressDialog.setMessage("Please wait while your profile updates")
progressDialog.show()
val fileRef = storageProfilePictureRef!!.child(firebaseUser!!.uid + ".jpg")
var uploadTask: StorageTask<*>
uploadTask = fileRef.putFile(imageUri!!)
uploadTask.continueWithTask(Continuation <UploadTask.TaskSnapshot, Task<Uri>>{ task ->
if (!task.isSuccessful)
{
task.exception?.let {
throw it
progressDialog.dismiss()
}
}
return@Continuation fileRef.downloadUrl
}).addOnCompleteListener (OnCompleteListener<Uri> {task ->
if (task.isSuccessful)
{
val downloadUrl = task.result
myUrl = downloadUrl.toString()
val ref = FirebaseDatabase.getInstance().reference.child("Users")
val userMap = HashMap<String, Any>()
userMap["fullname"] =
full_name_profile_frag.text.toString().toLowerCase()
userMap["username"] = username_profile_frag.text.toString()
userMap["bio"] = bio_profile_frag.text.toString()
userMap["image"] = myUrl
ref.child(firebaseUser.uid).updateChildren(userMap)
Toast.makeText(
this,
"Account information successfully updated",
Toast.LENGTH_LONG
)
.show()
val intent =
Intent(this@AccountSettingsActivity, MainActivity::class.java)
startActivity(intent)
finish()
progressDialog.dismiss()
} else {
progressDialog.dismiss()
}
}
)
}
}
}
}