java - 这个 Java 是否很好地近似了 @UIApplicationMain 在 Swift 中的工作方式?

标签 java swift startup

我试图理解 @UIApplicationMain 的自动魔力以及如何用 Java 可视化 iOS 应用程序的启动:

public class UIApplication extends UIResponder implements Runnable {   
    final UIApplicationDelegate appDel;
    public UIApplication(UIApplicationDelegate appDel) {
        this.appDel = appDel;
    }

    public static void main(String[] args) {
        try {
            UIApplication app = new UIApplication(new AppDelegate());

            handThisReferenceToOperatingSystem(app);
            iOSdoesSomethingLikeThis(new Thread(app).start());    
        } catch(Exception e) { e.printStackTrace(); }
    }

    public void run() {
        // chill-out and wait for iOS to invoke methods in UIResponder class.
        // The UIResponder methods invoke my custom methods in AppDelegate.
    }

            public static class AppDelegate implements UIApplicationDelegate {
                public void application(Object UIApplication) { // app specific behaviour
                }
                public void applicationWillResignActive(Object UIApplication) {   // app specific behaviour
                }
                public void applicationDidEnterBackground(Object UIApplication) {  // app specific behaviour
                }
                public void applicationWillEnterForeground(Object UIApplication) {  // app specific behaviour
                }
                public void applicationDidBecomeActive(Object UIApplication) {  // app specific behaviour
                }
                public void applicationWillTerminate(Object UIApplication) {  // app specific behaviour
                }
                // maybe more methods from the UIApplicationDelegate
            }

           public interface UIApplicationDelegate {
               void application(Object UIApplication);
               void applicationWillResignActive(Object UIApplication);
               void applicationDidEnterBackground(Object UIApplication);
               void applicationWillEnterForeground(Object UIApplication);
               void applicationDidBecomeActive(Object UIApplication);
               void applicationWillTerminate(Object UIApplication);
               // maybe some more methods ....
           }
}

public class UIResponder {
    void fingerSwipe() { // default implementation  
    }
    void verticalMotion() { // default implementation
    }
    // more methods iOS might invoke 
}

基本上,将 @UIApplicationMain 属性应用于 AppDelegate 类会使所有其他代码消失,对吗?

最佳答案

看看这个答案:https://stackoverflow.com/a/24516329/335974

要点是它生成 Objective-C 项目中的 main.m 文件:

int main(int argc, char *argv[]) {
    @autoreleasepool {
        NSString *appDelegateClassName = @"AppDelegate";

        return UIApplicationMain(argc, argv, nil, appDelegateClassName);
    }
}

因此,您的 Java 代码看起来与所发生的情况大致相同。

关于java - 这个 Java 是否很好地近似了 @UIApplicationMain 在 Swift 中的工作方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38884123/

相关文章:

ios - swift - 保存 plist 字典而不覆盖键

ios - 如何在 Swift 后台执行一个方法

asp.net-mvc - 加快 Web 应用程序启动时间的指针

c++ - 用户禁用的启动位置中的 WinAPI 和程序

java - Android:无法获取 API 的结果

java - java中如何让 Sprite 跳跃?

Java单例+内部类误读

java - setAutocommit(true) 进一步解释

swift - 从 Swift NSURLsession 的 Rest API 调用返回数据

c++ - 添加需要管理员才能启动的程序