Compilation Error: onActivityResult(int,int,Intent) in 'package.fool' clashes with onActivityResult in 'android.support.v4.app.FragmentActivity' - android

I have a simple Activity that i need to implement the method 'onActivityResult' but when I do that it's returned this message about the method i've implemented.
onActivityResult(int,int,Intent) in 'package.fool' clashes with 'onActivityResult(int,int,Intent)' in 'android.support.v4.app.FragmentActivity';
My Activity:
public class Agenda extends AppCompatActivity implements RecycleViewAdapter.Listener, FragmentDrawer.FragmentDrawerListener, PreferenceManager.OnActivityResultListener {
protected void onCreate(Bundle savedInstanceState) {
Log.d("OnCreate", "----------------------------------------");
super.onCreate(savedInstanceState);
}
}
I think that there are the same override method for more than two classes, according to this information:
Overrided Methods
I would be thankfull if someone help me =D.

Problem Solved!
Actually there was no need to implement:
PreferenceManager.OnActivityResultListener
Because this method is already implicity in the Activity and the fact that i implemented again the same method was causing the error.
Anyway, thanks for the comunity help.

Related

Nothing shows up while calling a method

I was developing an exam score calculator app.
When I want to call AD methods,advertisements don't show up.
Calculation process happens in OnCreate method:
public class resultActivity extends AppCompatActivity {
public String responseId;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
/*Calculation...*/}
and other voids like:
public void requestAd() {
/*AD RQUESTING PROCESS...*/
}
and
public void showAd() {
/*AD SHOWING PROCESS...*/
}
AD team gave me this code to call the method and it works well:
requestButton.setOnClickListener(v -> requestAd());
showButton.setOnClickListener(v -> showAd());
But the Problem is I don't have buttons to call them so I tried this:
public class resultActivity extends AppCompatActivity {
public String responseId;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
requestAd();
showAd();
/*Calculation...*/}
But when the activity starts ads don't show up!
The whole question is I want this methods to be called while this activity starts.
thank you.
Try building up the release version APK and test on it. Maybe your Ad-provider have some restrictions in debug version?
I made another class and moved request Ad and showAd there. Then, I made an object and called the method through object.
I have to mention that I changed a minor thing in requestAd but the main job was done by the object.
Thank You All.

Some sort of error

Something is wrong with my java file, but I don't know what it is. Can someone please tell me.
BTW, I'm new to this
Thank You
Screenshot
Closing braces are missing as far as i can see.
you need to give 2 closing braces after super statement
you are missing closing } braces.
put the 2 closing } braces after your onCreate() callback .
Example:-
package com.example;
import..
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

onResume() in BaseActivity is getting called in all the activities which extends BaseActivity

In my application, bluetooth device scanning code is written in onResume() method in BaseActivity.
I extended some activities with BaseActivity so, if I switch to any activities, bluetooth scanning is being done.
Is there any way to write onResume() in BaseActivity works only once? Please help me. Thanks in advance.
Thats how inheritance works. But you can overwrite the onResume in your subclas with an empty method.
#Override
public void onResume(){
// no super class is called
}
But i think there is something wrong with your program design.
try this:
public class BaseActivity extends AppCompatActivity {
static Boolean IsResumecalled = false;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
protected void onResume() {
super.onResume();
if (!IsResumecalled) {
IsResumecalled= true;
//write your code here
}
}
}
Your active Bluetooth connection should not reside in the BaseActivity. It rather should bind itself on his onCreate() via bindService to the BluetoothService - so it does not matter if one Activity destroys itself and the next one is getting started, because the Service is not Acitivity-dependent.
Look here for the general android developer guide on BluetoothService
https://developer.android.com/guide/topics/connectivity/bluetooth.html
And and how to use Services namely the bounded Service
https://developer.android.com/guide/components/services.html
There are also google code examples which you can use as a guideline.
It's a bad idea to block the onResume() call since it's a important part of the lifecycle for example if you minimize and maximize the app.
Override onResume in your child activities but do not call super.onResume()
#Override
public void onResume(){
// super.onResume(); // do not call this line in your child activities
}

Butterknife not detecting the source of event

I have just started working with Butterknife library and written the following code:
class myActivity extends AppCompatActivity
{
#BindView(R.id.button) Button app1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
public void selectApp(View b)
{
Button clicked=(Button)b;
if(clicked==app1)
Toast.makeText(this,"First App clicked",Toast.LENGTH_LONG).show();
}
}
here selectApp is attached through onClick in the xml view file.
But the problem is clicked==app1 is returning false even when pressing app1. The method is being called but the if condition is coming false.
Can anybody clarify.
Thanks
I think this would work:
if(clicked.getId()==R.id.button)
Also, you can use View b and not parse into a button:
if(b.getId()==R.id.button)
¿Is this your actual code? seems to lack an annotation on the method.

setOnClickListener for a button

Just getting started with Android development and I can't figure out why this won't work. Here is the error that I am getting (on the last line):
The method setOnClickListener(View.OnClickListener) in the type View
is not applicable for the arguments (MainActivity)
And here is the code. Seems pretty simple, but I don't see what the problem is. Can anyone help? Thank you!
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_myActivity);
View continue = findViewById(R.id.ContinueBtn);
continue.setOnClickListener(this);
}
}
Try this.
public class MainActivity extends Activity implements OnClickListener
When you pass this object into setOnClickListener then you need to implement OnClickListenere .
you have to do like this
public class MainActivity extends Activity implements OnClickListener {
/// code
}
first of all change the continue to some other name as it is the keyword you can't give a keyword as variable name
implements OnClickListener for your Mainactivity
Button continuea = (Button)findViewById(R.id.ContinueBtn);

Categories

Resources