以上就是给各位分享TheTargetofCocoaapplication,同时本文还将给你拓展AnapplicationsendstheWM_COPYDATAmessagetopassdatatoan
以上就是给各位分享The Target of Cocoa application,同时本文还将给你拓展An application sends the WM_COPYDATA message to pass data to another application、android – ApplicationStatus类E / SysUtils:ApplicationStat中的ApplicationContext为null、android – 尝试在Application类的实例上调用getApplicationContext()会导致null对象引用错误、Android 中this、getContext()、getApplicationContext()、getApplication()、getBaseContext() 之间的区别等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- The Target of Cocoa application
- An application sends the WM_COPYDATA message to pass data to another application
- android – ApplicationStatus类E / SysUtils:ApplicationStat中的ApplicationContext为null
- android – 尝试在Application类的实例上调用getApplicationContext()会导致null对象引用错误
- Android 中this、getContext()、getApplicationContext()、getApplication()、getBaseContext() 之间的区别
The Target of Cocoa application
想在我的application中添加AppleScript脚本,于是将写好的脚本添加到工程Resource目录下。
编译之后却发现,debug.app/Contents/Resource 路径下并没有包含我添加的脚本文件。
看了下面的文章之后,恍然大悟~~~
http://www.cocoachina.com/macdev/cocoa/2010/0120/347.html
相信很多人都注意到XCode中,有个Target的概念. 这在很多地方都有所体现,比如打开一个工程后,左侧的列表中有Targets一项,而在工程界面的顶部菜单中,project里面也有多个涉及到Target的项目,那么这个Target到底是什么呢?
Apple的人是这样说的:“ Targets that define the products to build. A target organizes the files and instructions needed to build a product into a sequence of build actions that can be taken.”
简单的理解的话,可以认为一个target对应一个新的product(基于同一份代码的情况下). 但都一份代码了,弄个新product做啥呢? 折腾这个有意思么?
其实这不是单纯的瞎折腾,虽然代码是同一份,但编译设置(比如编译条件),以及包含的资源文件却可以有很大的差别. 于是即使同一份代码,产出的product也可能大不相同.
我们来举几个典型的应用多Targets的情况吧,比如完整版和lite版; 比如同一个游戏的20关,30关,50关版; 再或者比如同一个游戏换些资源和名字就当新游戏卖的(喂喂,你在教些什么...)
Targets之间,什么相同,什么不同!
既然是利用同一份代码产出不同的product,那么到底不同Target之间存在着什么样的差异呢?
要解释这个问题,我们就要来看看一个Target指定了哪些内容.
从XCode左侧的列表中,我们可以看到一个Target包含了copy Bundle Resources,Compile Sources,Link Binary With Libraries. 其中
copy Bundle Resources 是指生成的product的.app内将包含哪些资源文件
Compile Sources 是指将有哪些源代码被编译
Link Binary With Libraries 是指编译过程中会引用哪些库文件
通过copy Bundle Resources中内容的不同设置,我们可以让不同的product包含不同的资源,包括程序的主图标等,而不是把XCode的工程中列出的资源一股脑的包含进去.
而这还不是一个target所指定的全部内容. 每个target可以使用一个独立,不同的Info.plist文件.
我们都知道,这个Info.plist文件内定义了一个iPhone项目的很多关键性内容,比如程序名称,最终生成product的全局唯一id等等.
而且不同的target还可以定义完整的差异化的编译设置,从简单的调整优化选项,到增加条件编译所使用的编译条件,以至于所使用的base SDK都可以差异化指定.
创建第二个Target!
为什么是第二个? 因为第一个就是创建好工程后的默认Target呀! (废话这么多,拖走...)
创建target有多种方法,我们可以从现有的target上复制出一份,然后略加改动,也可以完全新建一个target出来. 但其实说穿了,两个方法大同小异
首先我们来看看利用复制的方法创建target
利用复制创建target
我们在XCode左侧的列表中,展开 Targets 项,在现有的target上,右键选择 "Duplicate",或者选中现有target后,在顶部菜单的Edit内选择"Duplicate"也可以.
此时我们就得到了一个新的target,而在Resource里面也会得到一个 xxxx copy.plist. 这个新的target与原有的target是完全一致的,余下的就是一些差异化的修改,这个我们后面再说
创建全新的target
类似复制的方法,我们可以在左侧的列表中很多地方按下右键菜单,都可以看到Add中会有"New Target..."一项,而在工程顶部菜单的Project内,也可以看到这个"New Target..."的身影.
点击后,首先会让你选择target的类型,既然我一直所指的都是程序本身,那么自然选择Application了(至于其他的嘛,有兴趣的自己研究吧,比如我们可以把程序中的部分提取成一个Static Library).
Next后,会让你输入一个新的Target的名字,而不像复制的方法中,默认生成 xxxxx copy这样的target名.
但是这样生成出的Target几乎是空的. copy Bundle Resources,Link Binary With Libraries里面都没有任何内容. 编译设置也是完全原始的状态.
可以通过拖拽内容到这些target的设置中,以及调整编译选项来完成Target的配置.
Target中部分内容的修改方法! 其实这段的部分内容,在非多Targets的工程中也可能会用得到. 由于修改基本都是在工程/编译设置中完成,因此没有特殊情况,就不再声明了,打开target对应的工程/编译设置的方法可以采用在该target上右键,选择get info来做到. 生成的product名称的修改: Packing段内的Product Name一项 Info.plist文件名: Packing段内的Info.plist File一项,比如复制出来的target觉得那个xxxxx copy.plist太傻就可以在这里改 条 件编译: 增加一个user-defined Setting(Target "xxxx" Info的build页的左下角那个齿轮中可以看到这个内容),在Other C Flag里面填入,比如要定义一个叫做LITE_VERSION的define值,我们可以写上 "-DLITE_VERSION" 或 "-DLITE_VERSION=1". 那么在程序中就可以用 #if defined(LITE_VERSION) #else #endif 这样的条件编译来部分差异化代码了 也许有些朋友记得我在代码区贴过的检测破解版的代码,其中有一种检测方法就是看info.plist是文本还是二进制的,那么我们能否建议一个模拟破解的target,直接生成文本的info.plist以便测试呢? 当然可以,在packing段内,有一项叫"Info.plist Output Encoding",默认值是Binary,我们只要选成xml,那么生成出的product.app内的info.plist就直接是文本样式的了. 另 外,向copy Bundle Resources,Link Binary With Libraries内添加/删除文件,可以在要改动的文件上,选择get info,并且切换到Target页,勾选要引用这个文件的target即可. 比如icon.png可以指定给默认target,而icon_lite.png指定给lite verion的target
An application sends the WM_COPYDATA message to pass data to another application
对于只是在有VB,VC开发两个应用程序中传递数组如此简单的数据,没必要用什么DLL,内存映射之类的大刀吧
WM_copYDATA Message
--------------------------------------------------------------------------------
An application sends the WM_copYDATA message to pass data to another application.
Syntax
To send this message,call the SendMessage function as follows.
lResult = SendMessage( // returns LRESULT in lResult (HWND) hWndControl,// handle to destination control (UINT) WM_copYDATA,// message ID (WParaM) wParam,// = (WParaM) () wParam; (LParaM) lParam // = (LParaM) () lParam; );
Parameters
wParam
Handle to the window passing the data.
lParam
Pointer to a copYDATASTRUCT structure that contains the data to be passed.
Return Value
If the receiving application processes this message,it should return TRUE; otherwise,it should return FALSE.
The copYDATASTRUCT structure contains data to be passed to another application by the WM_copYDATA message.
Syntax
typedef struct tagcopYDATASTRUCT {
ULONG_PTR dwData;
DWORD cbData;
PVOID lpData;
} copYDATASTRUCT,*PcopYDATASTRUCT;
Members
dwData
Specifies data to be passed to the receiving application.
cbData
Specifies the size,in bytes,of the data pointed to by the lpData member.
lpData
Pointer to data to be passed to the receiving application. This member can be NULL.
转来的,还没经过测试呢,如果有问题概不负责!!!
android – ApplicationStatus类E / SysUtils:ApplicationStat中的ApplicationContext为null
E / SysUtils:ApplicationStat中的ApplicationContext为null
有谁知道ApplicationStatus类?我没有在我的项目中
它发生在我在openGL中快速渲染纹理时
解决方法
我的问题是在打开新意图时直接传递额外的变量,如下所示.
>调用代码:
intent.putExtra("markerdata: ",assetVO);
>接收代码:
markerdata = (HashMap<String,Object>) getIntent().getSerializableExtra("markerdata");
2天前升级到Android Studio 1.3后,我总是变为空.
所以我的工作是将传递的信息捆绑在一起:
>调用代码:
Bundle b = new Bundle(); b.putSerializable("markerdata",assetVO); intent.putExtras(b);
>接收代码:
Bundle extras = getIntent().getExtras(); markerdata = (HashMap<String,Object>) extras.getSerializable("markerdata");
现在它的工作原理.希望它可以帮助别人.
android – 尝试在Application类的实例上调用getApplicationContext()会导致null对象引用错误
我正在尝试在我的Android应用中进行一些网络连接.
导致我的错误的事件序列如下:
在我的片段中,我得到了我的VolleySingleton类的一个新实例,如果还没有.
public static VolleySingleton getInstance() {
if (vInstance == null) {
vInstance = new VolleySingleton();
}
return vInstance;
}
在创建VolleySingleton的实例时,我创建了一个请求队列并将其设置为等于Volley.newRequestQueue(myApplication.getContext());
public class VolleySingleton {
private static VolleySingleton sInstance = null;
private ImageLoader imageLoader;
private RequestQueue mRequestQueue;
MyApplication myApplication = new MyApplication();
private VolleySingleton() {
mRequestQueue = Volley.newRequestQueue(myApplication.getAppContext());
imageLoader = new ImageLoader(mRequestQueue, new ImageLoader.ImageCache() {
private LruCache<String, Bitmap> cache = new LruCache<>((int)(Runtime.getRuntime().maxMemory()/1024/8));
@Override
public Bitmap getBitmap(String url) {
return cache.get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
cache.put(url, bitmap);
}
});
}
public static VolleySingleton getInstance() {
if (sInstance == null) {
sInstance = new VolleySingleton();
}
return sInstance;
}
public RequestQueue getRequestQueue() {
return mRequestQueue;
}
public ImageLoader getimageLoader() {
return imageLoader;
}
}
现在,myApplication只是扩展Application的MyApplication类的一个实例,而getContext()只是在MyApplication的实例上调用getApplicationContext.以下是MyApplication类的代码:
public class MyApplication extends Application {
private static MyApplication sInstance;
public static final String API_KEY = "xxxxxxxx";
@Override
public void onCreate() {
super.onCreate();
sInstance=this;
}
public static MyApplication getInstance() {
return sInstance;
}
public Context getAppContext() {
return sInstance.getApplicationContext();
}
}
当我尝试返回sInstance.getApplicationContext()时,似乎发生了错误;
我已经设法获得相同的代码在一个单独的测试项目中工作,所以我在这里不知所措.
这是我的logcat:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.xxxxxxxxx.chessgame.Models.MyApplication.getApplicationContext()' on a null object reference
at com.xxxxxxxxx.chessgame.Models.MyApplication.getAppContext(MyApplication.java:28)
at com.xxxxxxxxxx.chessgame.Networking.VolleySingleton.<init>(VolleySingleton.java:25)
at com.xxxxxxxxx.chessgame.Networking.VolleySingleton.getInstance(VolleySingleton.java:42)
at com.xxxxxxxx.chessgame.RecyclerViews.FragmentViewOne.onCreate(FragmentViewOne.java:95)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1763)
at android.support.v4.app.FragmentManagerImpl.movetoState(FragmentManager.java:913)
at android.support.v4.app.FragmentManagerImpl.performPendingDeferredStart(FragmentManager.java:842)
at android.support.v4.app.Fragment.setUserVisibleHint(Fragment.java:859)
at android.support.v4.app.FragmentStatePagerAdapter.setPrimaryItem(FragmentStatePagerAdapter.java:152)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1071)
at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
at android.view.View.measure(View.java:17430)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:875)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17430)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:851)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2560)
at android.view.View.measure(View.java:17430)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2001)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1166)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1372)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FramedisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.Act
解决方法:
请确保您在应用程序标记中将清单中的MyApplication类声明为android:name =“packagename.MyApplication”
Android 中this、getContext()、getApplicationContext()、getApplication()、getBaseContext() 之间的区别
Android 中this、getContext()、getApplicationContext()、getApplication()、getBaseContext() 之间的区别
: 知之为知之,不知为不知是知也!
- 使用this, 说明当前类是context的子类,一般是activity application等;
this:代表当前,在Activity当中就是代表当前的Activity,换句话说就是Activity.this在Activity当中可以缩写为this.
Activity.this的context 返回当前activity的上下文,属于activity ,activity 摧毁他就摧毁
- 使用getApplicationContext 取得的是当前app所使用的application,这在AndroidManifest中唯一指定。意味着,在当前app的任意位置使用这个函数得到的是同一个Context;
getApplicationContext(): 返回应用的上下文,生命周期是整个应用,应用摧毁,它才摧毁。
- 使用getContext获取的是当前对象所在的Context, Context通常翻译成上下文,我通常当成场景来理解。
- getApplication():andorid 开发中共享全局数据;
- getBaseContext() 返回由构造函数指定或setBaseContext()设置的上下文
我们在平时的开发中,有时候可能会需要一些全局数据,来让应用中得所有Activity和View都能访问到,大家在遇到这种情况时,可能首先会想到自己定义一个类,然后创建很多静态成员,不过andorid已经为我们提供了这种情况的解决方案:在Android中,有一个名为Application的类,我们可以在Activity中使用getApplication(),方法来获得,它是代表我们的应用程序的类,使用它可以获得当前应用的主题,资源文件中的内容等,这个类更灵活的一个特性就是可以被我们继承,来添加我们自己的全局属性。
参考:
Android 中this、 getApplicationContext()、getApplication()之间的区别_梦之星辰-怀_新浪博客
http://blog.sina.com.cn/s/blog_a72ec20c0101coso.html
android 中 涉及到context的时候this和this.getApplictionContext的区别 - liuyun - ITeye技术网站
http://liuyun025.iteye.com/blog/1139970
关于The Target of Cocoa application的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于An application sends the WM_COPYDATA message to pass data to another application、android – ApplicationStatus类E / SysUtils:ApplicationStat中的ApplicationContext为null、android – 尝试在Application类的实例上调用getApplicationContext()会导致null对象引用错误、Android 中this、getContext()、getApplicationContext()、getApplication()、getBaseContext() 之间的区别等相关知识的信息别忘了在本站进行查找喔。
本文标签: