I am learning to develop an android app and while developing an android app. I came across a method setContentView(R.layout.activity_main); in MainActivity.java. The MainActivity extends AppCompactActivity.
So setContentView(R.layout.activity_main); is the one of the method found in AppCompactView?
Related
I have a running Android java written application and I would like to improve it.
For know my mainactivity, called DrugListActivty extend AppCompat. In short it's a recyclerView with Room database management.
I would like to move some part of the code in a MainActivity, in charge of checking database or onPause for example.
For now (and it's not working) I made :
public class MainActivity extends AppCompatActivity {
//some stuff
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, DrugListActivity.class);
startActivity(intent);
}
And DrugListActivity became
public class DrugListActivity extends MainActivity {
//etc
I have blink effect, DrugListActivty is launch again and again and again.
Is my idea bad (move to simply code)?
If is a good idea, there must be a right way to do it but I can't find any help.
So I'm asking the experts.
Thanks in advance for reading me, your advises and your time.
I have developed a game in android but now I want to make the gameplay or game screen in LibGdx as I am familiar with it. So, can I make game screen in LibGdx and use splash, login, setting screen etc. which are made in android ?
If Yes, Then how can I do so?
Let me answer your question again. You don't have to use core or desktop folders. You can code everything for Android folder with Ads, Play Services, etc. if you wish.
Let me describe how you do it.
Create a class that extends AndroidApplication this is your MainActivity class where everything starts.You add a game view and ad view to this class game view class extends Game class on create() method of AndroidApplication class.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
// create view that contains game
View viewGame = initializeForView(new MyGame(this), config);
// create ads
setUpAds();
layoutMain = new RelativeLayout(this);
// add game view
layoutMain.addView(viewGame, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
setContentView(layoutMain);
}
You set a class that extends ScreenAdapter insde create() method
of your MyGame class. and send instance of MyGame class to screen
classes as parameter to change screen using Game instance and
everything inside classes like Splash, Game, Setting or anything
else is coded in Java(Android) and you can easily change screens
using game.setScreen((new MainMenuScreen(game))); That's all the
logic.
I was tweaking the sample hello world app that android studio provides and found out that I cannot call the setContentView(R.layout.activity_main); outside any method.For example:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
setContentView(R.layout.activity_main); //compilation error
}
I know that I should not be calling setContentView outside onCreate(),but just for a reference I tried it out.I can figure out that this has something to do with Java and not android,but I can't seem to figure out the where the problem exactly lies.Any help will be appreciated.
As per activity life cycle onCreate() is the method called when the activity is first created
OnCreate() is the point where most initialization should go: calling setContentView(int) to inflate the activity's UI, using findViewById to programmatically interact with widgets in the UI, calling managedQuery(android.net.Uri , String[], String, String[], String) to
i wanted to make an app to block incoming call with the help of this blog http://androidsourcecode.blogspot.in/2010/10/blocking-incoming-call-android.html In this blog it only declares only the specific classes but there is no launcher activity like MainActivity.java . I imagine the launcher activity is look like this
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PhoneCallReceiver abc=new PhoneCallReceiver();
abc.onReceive(getApplicationContext(),getIntent());
setContentView(R.layout.activity_main);
}
}
But it seems this way it does not work. I figure out there is several answer on this topics in stackoverflow. But i don't find which will be my launcher activity and how my app running background continuously .Please give me some link of complete tutorial on this or give me some direction.Thanks in advance:)
I am having trouble trying to use 'requestFeature' in my FRAGMENT. My code is below, I am trying to set the actionbar as an overlay.
#Override
public void onCreate(Bundle savedInstanceState) {
getActivity().requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
I do not want to use a theme because I don't want the whole app to be effected, only this fragment in particular.
You have to call requestWindowFeature() before the setContentView() in the Activity's onCreate() method. This Activity is the one that your fragment is a part of.