Java-. NET
WINFORM/WPF, Android
Class inherits activity--class inherits Form
① Android.
If you have 2 activity in Android, you can jump from one activity to another activity.
Intent t=New Intent (mainactivity. this, otheractivity. class ); StartActivity (t);
Using the intent, the jargon is called intent.
The back mainactivity is the first window, the next one is about to open
Intent t=new Intent (a.this,b.class)
Then startactivity (t);
②winform
To be opened the form, instantiate it, and then show opens the
FormA a=new FormA ();
A.show ();
So Android is much like. NET programming
The structure of Android
In the SRC folder of the project, where the source code of Java is, the Gen folder is where the compiled code is generated
. NET when writing code is a. cs file, Java is a. java file
The. dll file is compiled, and the. class file in Java
We see that there is a Com.android.helloword folder below Src, where the source code is placed below.
This com.android.helloworld, dot notation, at the time of visualization, is the 3-layer folder, under the HelloWorld folder under the Android file under the COM folder
This directory can be specified in your new class, specifying the file directory structure at 1.
2 can specify the parent class, inherit him, Java use extends, subclass use the parent class thing use Super, own use this
. NET use: Can, subclasses use the parent object to use base, their own this
3 Specify the implementation interface, Java uses implements,.net or:
Java inherits and implements the interface
4 Specify the generation of the class, the default with no constructors, do not tick also does not matter, in the class, you can also quickly build constructors
You can right-click on your code, choose Source, then a menu, you can quickly open the tool menu by Alt+shift+s, there is also a place to generate properties
For Java properties, see the following code
Here I only wrote 2 private. .. , then use Alt+shift+s, generate attributes, generate parameters of the constructor, so Java code is relatively fast, but there is no. NET to write the word real-time prompt code just. But in Java you use ALT +, you can prompt the code, but you give the IDE a few words to pay attention to the case, do not match.
Writing a code in. NET, it is convenient to use SHIFT+ALT+F10 to import namespaces quickly without introducing a namespace, and. NET uses using to manually import
Write a code in Java, you can use Ctrl+shift+o to achieve the same effect, Java import manually using import
There is also a common shortcut key is the format code, the code is not neat when the. NET use of Ctrl+e+d,java ctrl+shift+f can be
. NET annotations with Ctrl+e+c, uncomment ctrl+e+u
Java comments and uncomment using ctrl+\
Probably the most common shortcuts I know at the moment are so much.
Well, how do you test the debugging process?
1. I am currently using a real phone to test, very fast, right click on your project, open run configurations
2
Double-click Android application to create a new profile, then you select your project and click Target
The first option is the real machine test options, then did not find my phone, but my computer installed pea pod software, seemingly pea pod to my computer installed what ADB Drive East, and then my phone can communicate with the IDE, you can test, your phone to open developer options
Every time I write the code, click Run, the phone will open the program, see the latest effect, if not installed, he will first install
There are log4java,log4net and other logging tools for Java and. NET, with debug classes and visualizers in wirelessly (Logcat)
Use log. What can log, and there is the severity of the log, where I is a shorthand for the info level, before selling that tag I define a constant, defined above, this is like a log label, where the tag equals main
So I can define a log filter in Logcat.
So my logcat here is the log text for the main tag.
About log debugging Getting started here, you're welcome to study.
Create an activity below and let you combine. NET, knowing how the files on Android depend on the association
Before you do that, talk about the activity's life cycle.
7 Methods of Oncreate,onstart,onrestart,onresume,onstop,onpause,ondestroy
In each class, you can override these methods of the activity parent class, by default a new class that inherits activity contains a OnCreate method, equivalent to the Xxx_load method of WinForm
protected void onCreate (Bundle savedinstancestate) { super. OnCreate (savedinstancestate); }
Here Super.oncreate write a line of code can bind this window interface, such as we bind activity_main this android XML layout file
Setcontentview (R.layout.activity_main);
So the interface and the logic behind the binding, open the Activity_main.xml file, one is the interface mode, one is the XML file mode
Interface mode, is not much like the visual mode of WinForm
Next we'll look at the backend code behind Android.
It's really like the XAML language behind WPF, so comparing Android to. NET WPF is still very graphic.
With the background class, with the layout XML file in the layouts file, you also need to include this new activity in the Androidmanifest file.
This name is the same as the background class name, not the same as the layout file name, using dot + Plus background class name, to form an activity in the Android configuration name
This idea and WIN8 application development also very much like, WIN8 application development time also has the configuration manifest file, can set the icon, the propaganda picture, other system permission disposition and so on, this file function you can also understand as the. NET website the global file, OK, you know has this file the entry function to be possible.
Speaking so much, it is estimated that there should be an Android mobile phone in hand, simply look at the life cycle of Android
You can create a new project that overrides the 7 life cycle methods of the parent class in the default activity, using the markup that is executed by the LOG.I print method for each life cycle. Next Operation Android Program, we look at the log
① Install the program, click on the icon to start
Summary: OnCreate - OnStart Onresume
② pressed the Little House button and went back to the desktop
Summary: OnPause onStop
③ Press and hold the small house key to display the history opener list, and then select the program that you just opened, this way to open the program
Summary: Onrestart- OnStart Onresume
④ mobile phone for a long time, the default black screen, hang up the state, the same as the ② situation
OnPause OnStop
⑤ Open after black screen, as in the case of ③
Onrestart- OnStart Onresume
⑥ point the Return key, exit the program
Onpause-onstop-ondestroy
Well, the first impressions about Android are roughly written here, if there are more than 10 people. NET Fellow with Android IDE build still have the problem I can write an Android 4.x development IDE alone to build notes